Using some standard WINDOWS visual components, this application
This project uses a collection of techniques commonly used to get
windows applications to display messages. Use has been made of system
objects (that 'know' how to behave).
What follows is a list of components needed for this application,
along with some properties that need to be set for those components.
Be systematic and TIDY placing your components.
- Place a label on your form, change it's name to
title, change it's font to Arial 50 point Red,
change it's caption to read 'Hello World!'
- Place a button, change its name to gidday1,
change it's caption to read 'Greeting 1'.
- Place a button, change its name to gidday2,
change it's caption to read 'Greeting 2'.
- Place a button, change its name to gidday3,
change it's caption to read 'Greeting 3'.
- Place a button, change its name to done,
change it's caption to read 'quit'.
The 'Quit' Button
DOUBLE-LCLICK on your QUIT button to open up an event handler
procedure, then type the following command inbetween the begin
... end of the procedure:
your program to test the button's
The 'most primitive' means of displaying a message in a windows application
is using a ShowMessage dialog box.
A more sophisticated dialog is a customizable MessageDialog box.
The simplified syntax for a MessageDlg box is as follows:
MessageDlg('message text',messageType,[set of buttons],0)
Where the messageType can be: mtWarning, mtError, mtInformation,
the buttons available are: mbYes, mbNo, mbOK, mbCancel, mbHelp, mbAbort,
mbRetry, mbIgnore, mbAll
- Open up an OnClick event handler for your Greeting 2
button and construct a MessageDlg command that has 'Hello
World' as the message, mtWarning at the message type
with mbOK, mbCancel and mbIgnore buttons.
- Compile and Run your project, once again noticing
that the MessageDlg box has FOCUS, yet will allow you to press any
of the buttons to make the dialog go away.
The third type of 'greeting' involves altering the caption
property of the label that is already displayed.
Many different types of visual components have 'text' or 'caption' properties
- these can ALL be altered at RUNTIME (that is whilst the program is
running) through the action of project code.
It is possible to respond to a particular button being pressed on
a MessageDialog - this uses the RETURN VALUE of the MessageDialog
(that is, each button on the MessageDialog generates a different code
if you press it.
- Alter the code that appears in gidday2Click to resemble
procedure TForm1.gidday2Click(Sender: TObject);
if messagedlg('Hello World',mtWarning,[mbOK, mbCancel, mbIgnore],0) = mrOk
then title.caption := 'ooroo';
- compile and Run the application to check the result.
The messageDialog actually generates a code that uniquely identifies
the button that was pressed to acknowledge the dialog box. By using
a simple test, we can logically branch from one action to the next,
depending on what button is pressed.
RETURN VALUES for messageDialogs are codes from the following
mrNone, mrAbort, mrYes, mrOk, mrRetry, mrNo, mrCancel, mrIgnore, mrAll