IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help


Our First Lazarus Project

Using some standard WINDOWS visual components, this application greets you.

the hello world form

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).

The Components:

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:

then compile and run your program to test the button's action

Greeting 1

showmessage dialog

The 'most primitive' means of displaying a message in a windows application is using a ShowMessage dialog box.

  • DOUBLE-LCLICK on your gidday1 button to open up an event handler procedure in the unit
  • Enter the following code:
    	ShowMessage('Hello World');
    into Gidday1Click procedure
  • compile and then run your project, and try out the button. You will notice that the ShowMessage dialog already has an [OK] button for you to confirm you have finished with the message. Notice also that the [OK] button of this dialog HAS FOCUS (that is, you must PRESS IT before doing anything else).

Greeting 2


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, mtConfirmation, mtCustom,
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.

Greeting 3

The third type of 'greeting' involves altering the caption property of the label that is already displayed.

  • In the ONCLICK event of your Greeting 3 button, place the following event handler code:
    	title.caption := 'Hi There!';
  • compile and Run the application to check the result.
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.

Final Touches

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 the following:
    	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 list:

	mrNone, mrAbort, mrYes, mrOk, mrRetry, mrNo, mrCancel, mrIgnore, mrAll

©Copyright t 1992..2018+. Edition 26.150117
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License