Lessons 45–46 · 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
45
Enabled and visible states of control objects
Textbook: pp. 98–101
GoalDistinguishes the Visible and Enabled properties, uses the logical values True/False and the not operation, and controls an application by hiding or disabling buttons.
New words
Visible: whether the object is shown on the window · VisibleEnabled: whether the object reacts to the user · EnabledTrue / False: the two values of the logical type · True / Falsenot: the operation that reverses a logical value · not
Explanation
Most controls have the properties Visible and Enabled; both are of the logical type and take only the value True or False. If Visible = False, the object is not shown in the window but still exists and the code can refer to it. If Enabled = False, the object is visible but greyed out and the user cannot work with it. With these two properties an application guides the user: it disables a button that is not needed now or hides it to save space. The not operation reverses a logical value, so the statement Label1.Visible := not Label1.Visible; shows and hides the text each time it is pressed. For an object to answer a click it must be both visible and enabled.
Worked examples
The window width is 400 and Button2.Visible = False. When Button1 is pressed: ⏎ procedure TForm1.Button1Click(Sender: TObject); ⏎ begin ⏎ Form1.Width := Form1.Width + 20; ⏎ if Form1.Width >= 500 then ⏎ begin ⏎ Button1.Enabled := False; ⏎ Button2.Visible := True; ⏎ end; ⏎ end; At the fifth click the width becomes 400+5·20 = 500: Button1 greys out and Button2 appears.
Label1.Visible := not Label1.Visible; At the start the Label is visible (True). The 1st click hides it, the 2nd shows it; after an odd number of clicks it is hidden, after an even number it is visible. After 7 clicks the Label is hidden.
Class activity
“The hidden button”: in a two-button application the first button hides or shows the second; another pair predicts the state after 9 clicks.
Practice
1
Which property becomes False for an object to grey out?
Enabled
2
The Label is visible. If switching with not is done 5 times, what is the state?
Hidden (False)
3
The window grows from 400 by +20 per click; Button1 is disabled when the width reaches 500. After how many clicks?
5
4
Why can code still refer to a hidden object?
Visible = False does not delete the object, it only stops showing it; the object still exists.