Lessons 39–40 · 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
40
Practical lesson
Textbook: p. 92
GoalCreates applications with several buttons: changes the window size and position with buttons and calculates the result in advance.
New words
button panel: several buttons grouped for related actions · tugmalar blokistep: the amount a value changes with one click · qadamtest: running the application and comparing the result with the expected one · sinovcomment: a note to the reader inside the code · izoh
Explanation
In this practical lesson a four-button application, the “Window pilot”, is created: “Right”, “Left”, “Down”, “Up”. With each click the window moves 10 pixels: right – Left +10, left – Left –10, down – Top +10, up – Top –10. Each button’s OnClick procedure gets one statement, for example procedure TForm1.Button3Click(Sender: TObject); ⏎ begin ⏎ Form1.Top := Form1.Top + 10; ⏎ end; Run the application with F9 and press the buttons one after another: compare the movement of the window with the result you calculated. To understand why some buttons do not work, first check the button names in the Object Inspector and then the procedure name (Button1Click, Button2Click …): each procedure must belong to its own button.
Worked examples
Start: Left = 200, Top = 100. Buttons pressed: right 3 times, down 2 times, left 1 time. Left = 200+3·10–1·10 = 220, Top = 100+2·10 = 120.
Changing the step: if Left + 25 is used, four clicks move the window 4·25 = 100 pixels. A big step gives fast movement but makes exact placing harder.
Class activity
“The pilot’s route”: a pair writes a route of 6 button presses; another pair calculates the final Left and Top and checks them with the application.
Practice
1
Which property changes so the window moves down?
Top
2
Left = 150 and “Right” was pressed 5 times (step 10). What is Left?
200
3
Top = 300 and “Up” was pressed 4 times (step 10). What is Top?
260
4
Why does the application work wrongly if a button’s procedure is attached to another button?
The command of another button runs instead of the pressed one, so the movement is not as expected.