|
|
Section 4 - Linking controls to activity
Controls have a public interface which is the part of the control that is interesting to us as programmers. Clearly a component like a
button has a lot of internal code which must be run in order to draw the button in its various states (up, down. selected, deselected,
disabled etc). however, as programmers, we are more than glad not to have to concern ourselves with the innermost workings of the
controls, in much the same way as we are not generally interested how t
he internal combustion engine works in the family runabout... We do however care about what we need to do to make it stop and go! This
visible surface of a control comprises three sets of elements:
A) The Properties (equivalent to variables)
B) The Methods (equivalent to procedures and functions)
C) The Events
We can make our components "do something" by activating or calling their methods, or by changing the value of one or more
properties. Events are (as the name suggests) things that happen to our components. As we have already seen, all the components have a
default event, but most have many more than one. The events that a component can respond to are listed on the second of the two tabs
displayed in the object inspector window. Shown are the events that a form can generate, which you as the programmer can respond to by
providing code to run whenever the event occurs.
Delphi will create the basic procedure to handle the event, if you double click to the right of the event for which you wish to
write a handler. For example, if you wanted the form to minimise itself any time the user elected to double click on it, then you would
find the OnDblClick event (shown ringed in red) and double click to the right of it. Delphi will immediately write the header for the
procedure, giving it a sensible default name, and you will find that the program editor window appears automatically, with the cursor
positioned, ready for you to add your code. Clever stuff!
All you would need to do would be to add one line of code, to tell set the form's window state property to minimized. There is a constant
for this (wsMinimized) so the the line would read:
Form1.WindowState := wsMinimized;
It is well worth spending some time reviewing the events that each of the components can respond to, you will find that many of them
have
events in common. For example, many components can respond to being resized, or clicked, or double clicked. Those that respond to being
clicked can also respond to the mouse button being pressed down and the mouse button being released. Experiment now... Dro
p a few components on to the form, and find out which events they can respond to.
In particular, drop a timer object onto your form (this appears as a clock face on the system tab), and have a look at the events
that can generate/respond to.
|
|
|
|
|