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

Algorithms and Programming - Commands

Command | Property | Event Glossary | Graphics | Contribute

The 30 Second Guide to useful visual commands:

Command data type Notes
showmessage('hello world');   displays a standard dialog (with an ok button) and your message
messagedlg('hello world',messagetype, [buttons],1 ); word message types include mtWarning, mtError, mtInformation, mtConfirmation; buttons include mbYes, mbNo, mbOk, mbCancel, mbHelp, mbAbort, mbRetry, mbIgnore; return types match the buttons and take the form mrYes, mrNo and so on.
You can test what button was pressed:
if messagedlg('whaddyoureckon?',mtConfirmation, [mbYes,mbNo],1) = mrYes
then {do something}
inputbox ('title','prompt','default value') string Displays a diaglog box on the screen with 'title' in ot's title bar, 'prompt' above an edit box and 'default value' displayed inside the edit box. Used to harvest a value from the user in a controlled way. Usually used as part of an assignment statement like:

xstring := inputbox('Data Entry','Please enter a test score','0'); {to harvest a string value or}
x := strtoint(inputbox('Data Entry','Please enter a test score','0')); {more risky if the user doesn't type a number}
inttostr(x) string converts a whole number (integer) into text - necessary if displaying integers in labels, edit boxes and other text displays
strtoint('42') integer converts strings to integers - crashes if the conversion is not possible
strtointDef('42',-1) integer converts the string to an integer IF POSSIBLE, if not, returns the default numeric that is the second parameter (-1 in the supplied example)
floattostr(y) string converts a floating point decimal number (real) into string
strtofloat('4.5') real converts a string into a real, crashing if not possible
floattostrF(thing, ffcurrency,7,2);

floattostrF(thing, fffixed,7,2);


floattostrF: the formatted conversion builtin function where

  • thing: the floating point variable being converted into currency display
  • ffcurrency: the builtin currency format (includes the decimal point and a $ sign at the start of the number); fffixed lets you control the decimal places without inserting a $
  • fffixed allows you to determine the number of decimal places without also preceding the number with a $ sign
  • 7: a value indicating it is a single precision real currently
  • 2: the number of relevant decimal places
strtofloatdef(thing, defaultvalue); real converts the string to an real number IF POSSIBLE, if not, returns the default numeric that is the second parameter
trunc(x) integer tears the decimal off a real number leaving a whole number
p mod q integer delivers the REMAINDER of the division (eg. 9 mod 7 = 2)
p div q integer returns the whole answer to the division p/q (eg 9 div 7 = 1)
ord(x) integer/byte turns a character into it's corresponding ASCII number
char(y) char converts a number into the corresponding character from the ASCII table
thing as objecttype

eg: sender as TImage
  one way of typecasting an unknown sender as a recognisable data type (and therefore playing with it's properties)
thing is objecttype

if sender is TImage
then ...
boolean a way of testing the datatype of an unknown object - used in a test, usually (an if..then)
random(x) numeric used to create a random number (in the range 0..x-1). Usually used in assignment statements like:
dice := random(6)+1
randomize   used to 'seed' the random number generator ensuring a different sequence of random digits each time the random function is called
PlaySound('file.wav',0,0) uses mmsystem plays the WAV file directly from your project (as an excusive process)
SndPlaySound('file.wav',snd_async); uses mmsystem plays the WAV file directly from your project (with other processes active also)
length(stringvariable) byte function returns the number of characters in the nominated string - a little like the expression ord(stringvariable[0])
pos(substring,superstring) byte returns the character position of the first character of the nominated substring in the superstring. Returns 0 if not found - important to test for this.
delete(sourcestring, startingchar, numchars); string surgically removes a piece from a nominated sourcestring, starting at a nominated startingchar number, removing the nominated numchars. The sourcestring "heals" itsef around teh removal, becoming shorter.
insert(substring, destinationstring, position); string surgically inserts the substring into the destinationstring at the mominated position - pushing all subsequent characters along to make room.
WinExec('filename',SW_SHOWNORMAL);   runs the named program - you need to include a path if the exe is not in the folder of the current applicaiton

The 30 Second Guide to useful visual properties:

Useful Property data type Notes
clientheight integer the number of pixels high your current form is
clientwidth integer the number of pixels wide the current form is
thing.top integer the number of pixels from the top of the form the thing is
thing.left integer the number of pixels from the left hand edge of the form the thing is
thing.width integer the number of pixels wide the thing is
thing.height integer the number of pixels high the thing is
thing.visible boolean whether thing can be seen or not (invisible things DO NOT respond the click events)
thing.enabled boolean whether thing can be used or not (a disabled button cannnot be clicked on, a disabled edit box isn't editable etc)
thing.controls[0..n-1] control array If a container object (like a form or a panel) has a number of owned controls, then the NUMBER of then can be accessed by thing.controlcount and each of them can be accessed via thing.controls[index] where index is a number between 0 and (thing.controlcount-1) . NOTE this is a similar scheme used to get a COMPONENTS in the components array

The 30 Second Guide to useful visual events:

Useful Event Notes
onclick triggered when the left mouse button is depressed whilst the mouse pointer is over the component (der)
onmousedown detects the pressing of the mouse button
onmousemove detects when the mouse pointer moves over the component
ontimer used with a timer object - it is the 'tick' of the timer that can be programmed to do things regularly (a form of iteration or loop)
onkeypress used to detect a keyboard event. Usually includes some form of decision structure (case statement most likely) to classify actions based on what key was pressed). The key comes in as a CHAR and we use this to detect normal typing keys
onkeydown used to detect a keyboard event. The key comes in as a NUMERIC CODE (called a virtual key code) that we can use to detect the EXTENDED KEYS (vk_up, vk_escape and so on) and also delivers the state of the shift

Contribute a Command

Given names:
E-mail address:
Enter the Command example here:

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