LearnStanmorephysics

Grade 10 · Delphi Foundations

Your first program

Grade 10 · Meet Delphi · Lesson and coding task · about 10 minutes

Open this task in the Delphi workspace →

Time to write your first Delphi code. There are two easy ways to show output:

1. A message dialog — pops up a little window with an OK button:

ShowMessage('Howzit, world!');

2. A memo — a white box on the form that can show many lines. You add one line at a time:

memOutput.Lines.Add('This appears in the memo');
memOutput.Lines.Add('And this is the second line');

Notice three things that Delphi is strict about:

  • Text (a string) goes between single quotes: 'like this'.
  • Every statement ends with a semicolon ;
  • Your code lives between the begin and end; of the event handler.
Try it. Press F9 (or click ▶), then click the button on the running form — that fires your event handler exactly like in Delphi.
Where is the rest of the unit? In the real IDE your handler sits inside a bigger file with unit, interface and implementation sections that Delphi writes for you. Here (as in the exam skeletons) that plumbing is managed for you — you edit exactly the part you would type at school, and the line numbers in error messages match what you see.

What you will do

Hints
  1. ShowMessage('…'); pops up the dialog — put your text between the single quotes.
  2. memOutput.Lines.Add('…'); adds one line to the memo. Call it twice for two lines.
  3. Check your spelling and punctuation exactly — 'Hello, Mzansi!' has a comma and an exclamation mark.
Model solution
procedure TfrmGreet.btnGreetClick(Sender: TObject);
begin
  ShowMessage('Hello, Mzansi!');
  memOutput.Lines.Add('Welcome to Delphi!');
  memOutput.Lines.Add('Programming is lekker!');
end;

About this material

This platform provides original CAPS-aligned practice material and study tools. Content is machine-verified and has not been reviewed by subject specialists. It is not affiliated with or endorsed by the Department of Basic Education. Learners should also use official past papers and consult their teachers where uncertain.