Enabled and visible states of control objects
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.
| Property = False | Result |
|---|---|
| Visible | the object is not shown but still exists |
| Enabled | the object is visible but greyed out – cannot be used |
In an online application the “Send” button stays grey and cannot be pressed until all required boxes are filled in. Once they are filled, the button turns normal. This prevents sending an incomplete form.
Web and app developers, designers of bank forms and game menu designers switch off or hide unneeded buttons for a time.
Write two “not yet” rules in your notebook, for example “the Next button stays grey until an answer is chosen”, and test each rule by asking a friend to play the user.
1procedure TForm1.Button1Click(Sender: TObject); 2begin 3 Form1.Width := Form1.Width + 20; 4 if Form1.Width >= 500 then 5 begin 6 Button1.Enabled := False; 7 Button2.Visible := True; 8 end; 9end;
“The hidden button”: in a two-button application the first button hides or shows the second; another pair predicts the state after 9 clicks.