Lessons 41–42 · 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
41
The ShowMessage window
Textbook: pp. 93–95
GoalShows the user a message with ShowMessage, sets a limit with if…then…else and uses IntToStr to join a number to text and write it in the title.
New words
ShowMessage: a procedure that shows a small window with a text message · ShowMessageIntToStr: converts an integer to a text string · IntToStrif … then … else: runs one statement when a condition is true and another when it is false · if … then … elsestring: a sequence of characters, written in single quotes · satr
Explanation
If the window grows without limit every time the button is pressed, it leaves the screen; a condition must be set. The conditional statement: if Form1.Width < 700 then … else … – if the condition is true the first part runs, if false the part after else runs. To tell the user the reason, ShowMessage('text') is used: it shows a separate small window and the application waits until OK is pressed. Inside a string write only Latin letters and ordinary signs; the Uzbek ‘ sign can be confused with the single quote. To show the window size in the title, the number is converted to text: Form1.Caption := 'Eni: ' + IntToStr(Form1.Width); without IntToStr, 'Eni: ' + Form1.Width is an error, because a number cannot be added to text. Check the condition first and only then change, so that the application does not pass the limit.
Worked examples
procedure TForm1.Button2Click(Sender: TObject); ⏎ begin ⏎ if Form1.Width > 300 then ⏎ begin ⏎ Form1.Width := Form1.Width - 20; ⏎ Form1.Height := Form1.Height - 10; ⏎ end ⏎ else ⏎ ShowMessage('Oyna yetarlicha kichik'); ⏎ end; A “Shrink” button. The starting size is 500×350: after 10 clicks the width is 500–10·20 = 300 and the height is 350–10·10 = 250; at the 11th click 300 > 300 is false, so the message appears.
Size in the title: Form1.Caption := 'Olcham: ' + IntToStr(Form1.Width) + ' x ' + IntToStr(Form1.Height); When the window is 600×350 the title becomes Olcham: 600 x 350. This line must be written after the size is changed, so that the title shows the new numbers.
Class activity
“The border guard”: a pair writes the application with the limit set at 500 pixels and calculates in advance at which click the message appears.
Practice
1
Which function converts a number to text before it is added to text?
IntToStr
2
The width starts at 500 and shrinks by 20 per click with the condition Width > 300. At which click does the message appear?
11
3
What does ShowMessage('Salom') do to the application?
It shows a message window and the application waits until OK is pressed.
4
Why is 'Eni: ' + Form1.Width an error?
Text and integer are different types; the number must be converted to text with IntToStr.