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

Lazarus Interaction

messages, dialogs
and displays

Visual | Console

Visual Programming - Hello World?

The world of visual programming provides the programmer with many ways to communicate with the user - most of them, however, require manipulation of TEXT (or string functions).

Form fields.

Painting output (messages, answers and other textual information) directly on to some visual component on the form is extremely common. Many components are custom built for this: Labels, Edit Boxes, Memo Boxes and SpinEdits and the like. The only real trick is knowing what textual property to tweak at runtime to display your messages. If you want to display NUMBERS, you must change them into text BEFORE trying to display them - the most common routines to do this are inttostr() for whole numbers and floattostr() for decimal numbers. If these conversions are handled badly, your program can crash rather messily.

The list of components below can be used for OUTPUT and INPUT (with the exception of a label) as, unless you configure them differently, the user can edit what is displayed in them.

  • Labels have a .caption property that allows you to change the displayed text in them

    eg: answer.caption := 'hello world';

    These cannot be used for INPUT in a project directly, only output.
  • Edit Boxes have a .text property to play with

    eg: answer.text := 'hello world';

    Keep in mind that edit boxes allow the user to edit the text in them also - a cursor appears and they can type directly into these text contianers. This might be what you would like to have happen, else you could disallow edits or disenable the box.
  • Memo Boxes are nifty text output spaces because they can contain vast quantities of text (paragraphs and paragraphs) and have many built-in methods to allow you to effectively manage the text displayed in them. The text in a memo box is stored in the .lines property and to add a line to the memo box, you use the .add method

    eg: answer.lines.add('hello world');

    A memo box can be thought of as a notepad space for the user - they can type and edit text there unless you configure it differently.
  • Spinedits are DIFFERENT in that they only allow you to display WHOLE NUMBERS in their .value property

    eg: answer.value := 42;

    By default they display with an up/down arrow to allow you to dial an appropriate value as well (unless they are configured differently by you).
  • Exotica: Many other components have .caption properties that also allow you to display textural messages (panels, images, checkboxes etc). Visual programmers typically employ controls that are intuitive for the user (well, that is the theory) - the input/output style should match something that is useable and in-keeping with the sort of information being manipulated.

Dialog Boxes.

The simplest OUTPUT dialog box is the showmessage('<text>'); command. It pops a dialog box up with your message in it and an OK button to make the box go away when you are done:

eg: showmessage('hello world');

This command is primitive and UGLY (ie. you have little or no control over how it looks and behaves). Good prorammers use these output boxes carefully.

The simplest INPUT dialog box is the inputbox('<title>','<Prompt>','<Default Value>'); command. This box pops up with a pre-built edit field for the user to type their value, by default the cursor is ready to type. You also get an OK and Cancel button for when you are done:

eg: replystringvariable := inputbox('Input Age','How old are you?','0');

The messagedlg('<text>',messagetype, [buttons],1 ); box is the most flexible of the lot (excepting creating a form that is completely customizable) and allows you to select from a number of standard windows message types, include buttons that you like and can be programmed to do different things depending on the button pressed:

eg: messagedlg('Hello World',mtWarning, [mbOk, mbCancel, mbhelp],1

Error handling and more powerful use of these dialogs will be covered in class exercises.


It is possible to DRAW graphics onto your form live at runtime.

work in progress - more here soon

Console Interaction In General

WE WILL NOT USE Console applications in this course - this section is included merely for completion.

When a Lazarus Console Application is running, a TEXT WINDOW (measuring 80 characters by 25 lines) is opened up on the user's desktop. This window has a MAXIMISE and MINIMISE button, along with a CONTROL BOX, and will also insert HORIZONTAL and VERTICAL SCROLL BARS should output fall outside the confines of the display

Console Applications in Lazarus interact with the user via OUTPUT statements that cause characters to be printed to the client window; and INPUT statements that accept typed characters from the keyboard, placing them into pre-declared containers (variables).

This varies signifigantly from Lazarus forms based projects, which use visual components (like buttons, text fields, scrolling windows etc.). These are covered above.

write[ln] - Console OUTPUT

The standard method of outputting to the screen is using a write[ln] statement. The two variations of this statement (write and writeln) vary in their action in that writeln terminates with a [cr]+[lf] whilst write does not.


write (expression {, expression});

writeln [(expression {, expression})]

Clearly, an expression could be a string expression (ie. something contained in a set of 'quotes'); a mathematical expression (eg. 42*6) or a variable expression (eg. 42*X).

The write syntax DEMANDS a bracketed expression or sequence of them, whilst the writeln may be used on it's own. Writeln, when used as a statement, either brings the cursor to a newline on the left margin of the output window (if it follows a write request); or leaves a blank line in the output - this provides very PRIMITIVE output formatting.


writeln ('hello') ------> hello
writeln (256:5) ------> 256
writeln (maxint) ------> 32767
write('hi','there') ------> hithere_
write('hi'); write('there') ------> hithere_
write('it''s a lie') ------> it's a lie_
write('''It''s a lie'', he said') -----> 'It's a lie', he said_

note: it is possible to output the answers to complex expressions

eg. writeln(24*16/sqrt(444/2) = 42) will result in the output FALSE


It is often useful to provide assignment values during the running of the program (in essence to 'feed the program' in real time) using an input statement of some kind.

An input stream might look like this:


Items in an input stream are delimited by some means (usually a space character) into separate pieces of information which are type specific.

Things that are considered to be delimiters by Lazarus are 'unexpected' characters (ie. a space in a number, a enter at the end of a line...)

The Read[ln] command instructs Lazarus to fetch, from the input device, a value to be subsequently assigned to a variable.

Input streams can originate from many sources (keyboard by default, disk or other peripheral also).

All 'extra' input (ie. info not directly assigned) is discarded.

If insufficient input is provided, Lazarus will 'hang' until the remainder is entered (or the machine is re-booted)


read([source,] variablename {, variablename} );

readln [([source,] variablename {, variablename} ) ];

where source = input|con|trn|kbd|(none)

The sources input,con and trn are all standard sources. The kbd source prevents the typing being echoed to the screen

A readln; without a source pauses a program until an enter key is pressed.


©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