Sign in Join
Wiki copytemporary

TLabel

Deutsch · English · Français · Suomi · Русский · 日本語

TLabel is a component that creates a text-item with one or more lines on another component. A TLabel is a descendant of TGraphicControl and is available under the Standard tab of the Component Palette.

Usage

A TLabel is one of the most basic components that can be used on forms. Most labels are the marking of other components, such as Edit fields, Memos, StringGrids and so on. TLabels provide a variety of events available to you but not required in most cases.

You can add a label to your form, by clicking the TLabel (text symbol Abc) on the Standard component palette and place it with a click on your form.

To change the default label Label of a new inserted TLabel on a form, you can proceed as follows:

Change caption at run time

Of course, you can change the caption (the text displayed) during run time.

The following example demonstrates this:

pascal
procedure TForm1.Button1Click(Sender: TObject);
const Cnt: Integer = 0;                     //Counter to determine how many times the button has been clicked
begin
  inc(Cnt);                                 //Increment the counter by 1
  Label1.Caption:='Button was clicked ' +   //Write the text on the caption of Label1
    IntToStr(Cnt) + ' times';
end;

Delphi incompatibility for right-aligned labels

Comments

To represent a multiline text, you need to insert at the appropriate place in the string a LineEnding as a word wrap signal. Example:

pascal
Label1.Caption := 'This' + LineEnding + 'is' + LineEnding + 'a' + LineEnding + 'multiline' + LineEnding + 'text';

See also


From the Free Pascal wiki, page "TLabel", as it stood on 2022-11-30 after a change by Ondrej, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.