[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] Reference for unit 'Controls' (#lcl)


The text displayed for the control.


Source position: controls.pp line 1768

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


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:

    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



Returns the Caption property.



Sets the value for the Caption property.



Copy the Text property into Buffer.



Updates the Text property from a PChar buffer.



String with the text or caption for the control.



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