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

The control button

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 (code below). 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.

Pascal
1procedure TForm1.Button3Click(Sender: TObject);
2begin
3  Form1.Top := Form1.Top + 10;
4end;
💡 Where will I use this?
In real life

A game character moves with arrow buttons, one square per press. If the buttons are pressed three times right and once up, you can work out where the character will be without playing. Programmers use this to check in advance that a program works correctly.

Who uses it

Game programmers and developers of robot vacuum cleaners and map apps calculate movement as a series of steps.

Try it today

On squared paper mark a starting square and let a friend say commands such as “right, right, up”; before moving the pencil, say in advance which square you will end on.

Worked examples
ButtonPressesChange
Right3Left + 30
Down2Top + 20
Left1Left – 10
ResultLeft = 220, Top = 120
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?
2
Left = 150 and “Right” was pressed 5 times (step 10). What is Left?
3
Top = 300 and “Up” was pressed 4 times (step 10). What is Top?
4
Why does the application work wrongly if a button’s procedure is attached to another button?
Story of the Week · The Khwarizmi WayDoes salt make water boil faster?Close the week: all of this week’s subjects in one storyRead →