Unit 'Controls' Package
[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] [#lcl]

TControl.Caption

The text displayed for the control.

Declaration

Source position: controls.pp line 1793

public property TControl.Caption : TCaption
  read GetText
  write SetText
  stored IsCaptionStored;

Description

Caption is a TCaption property with the text displayed for the control. By default, Caption has the same value as the Name property used for the control. An explicit value can be assigned at design-time using the Object Inspector, or by the developer in program code.

Controls normally use the Caption or Text properties (they are equivalent in TControl) to read or write their textual value. The property value is retrieved using either the RealGetText method, or the GetTextBuf method when it has been overridden in a descendent class. Conversely, the property value is stored using either RealSetText, or an overridden SetTextBuf method in a descendent class.

When the value in Caption is changed, a CM_TEXTCHANGED message is performed for the control. Changing the value for the property causes the caption for the HostDockSite to be updated (when assigned).

Caption can be used to display an accelerator (or shortcut) key which allows the control (or an associate) to be given focus or executed. The shortcut key is identified by placing an Ampersand (&) character in front of the character used as the accelerator key. Use two Ampersand characters to display a single Ampersand which is not a shortcut key. For example:

{
  var
    ALabel: TLabel;
    Form1: TForm;
    Memo1: TMemo;
    ...
}
ALabel := TLabel.Create(Form1);
ALabel.ShowAccelerator := True;
ALabel.FocusControl := Memo1;
ALabel.Caption := '&Notes && Comments';

Displays the 'N' character with an underline indicating the accelerator key. Pressing Alt+N activates the shortcut key and causes the associated TMemo control to be given focus.

Set values in Font to specify the typeface, size, color, and style used to display the Caption text.

See also

TControl.RealGetText

  

Returns the Caption property.

TControl.RealSetText

  

Sets the value for the Caption property.

TControl.GetTextBuf

  

Copy the Text property into Buffer.

TControl.SetTextBuf

  

Updates the Text property from a PChar buffer.

TControl.Text

  

String with the text or caption for the control.

TControl.Font

  

The font to be used for text display in this control.