AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Contents · Computing

The Label object

Lessons 43–44 · 2 lessons · N. I. Taylaqov (general editor), A. B. Akhmedov, M. D. Pardayeva, A. A. Abdug‘aniyev, U. M. Mirsanov. Informatics and Information Technologies, Grade 10, 1st edition. “Extremum-Press”, Tashkent, 2017
43

Placing information in the application window

Textbook: pp. 95–98
GoalPlaces a Label on the window, changes its Caption, Font and Name properties and shows a result through the Label while the application runs.
New words
Label: a control that shows text which the user cannot edit · LabelName: the property that holds the name of an object, used to refer to it in code · NameFont: the property group for the type, size and colour of text · Fontobject.property: the way to refer to a property of an object in code · obyekt.xossa
Explanation

The simplest tool for showing information in an application is the Label (on the Standard tab). Its main property is Caption: it holds the text that appears on the screen. Left, Top, Width, Height set the position and size, and Font sets the type, size and colour of the text (for example Font.Size, Font.Color). Every object has a Name property: Delphi names the first label Label1 and the second Label2. In code an object is referred to as “Name.property”, for example Label1.Caption := 'Salom'; do not change the Name property while the application runs, because the statements that refer to it stop working; give new names only when the object is being placed on the window. To show a number in a Label, first convert it to text: Label2.Caption := 'Eni: ' + IntToStr(Form1.Width);

💡 Where will I use this?
In real life

At the top of a school quiz app there is a line “Score: 3” that changes after every answer. It is shown through a Label: the program replaces its text with the new result. The user always sees the current result.

Who uses it

App developers, makers of electronic scoreboards and designers of control panels show results as text.

Try it today

During a game write the score on a sticky note and replace it with a new one after each round: a Label works the same way.

Worked examples
Pascal
1procedure TForm1.Button2Click(Sender: TObject);
2begin
3  Form1.Width := Form1.Width - 25;
4  Form1.Height := Form1.Height - 15;
5  Label1.Caption := 'Eni: ' + IntToStr(Form1.Width);
6  Label2.Caption := 'Boyi: ' + IntToStr(Form1.Height);
7end;
“The size indicator”: the window is 500×300, with a “Shrink” button and two Labels – code above. After four clicks: width 500–4·25 = 400, height 300–4·15 = 240, and the labels read “Eni: 400” and “Boyi: 240”.
A button that enlarges the text: Label1.Font.Size := Label1.Font.Size + 3; if the starting size is 10, after five clicks it is 10+5·3 = 25. Giving colour: Label1.Font.Color := clRed; the text becomes red.
Class activity

“The live caption”: a pair builds an application with a Label; one button enlarges the text, another shrinks it and the current size is shown in a second Label.

Practice
1
Which property holds the text shown by a Label?
2
Label1.Font.Size = 12 at the start. If +3 is added 4 times, what is the size?
3
What text does Label2.Caption := 'Eni: ' + IntToStr(400); give?
4
Why should the Name property not be changed while the application runs?
Story of the Week · The Khwarizmi WayDoes the paper reach the Moon?Close the week: all of this week’s subjects in one storyRead →