Placing information in the application window
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);
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.
App developers, makers of electronic scoreboards and designers of control panels show results as text.
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.
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 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.