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
beginandend;of the event handler.
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
- Use ShowMessage to pop up: Hello, Mzansi!
- Add the line Welcome to Delphi! to the memo
- Add a second memo line: Programming is lekker!
Hints
- ShowMessage('…'); pops up the dialog — put your text between the single quotes.
- memOutput.Lines.Add('…'); adds one line to the memo. Call it twice for two lines.
- 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;