Grade 10 · Meet Delphi · Lesson and quiz · about 8 minutes
Welcome! If you take Information Technology in Grades 10–12, Delphi is the language you will live in for the next three years — it is the language used in the CAPS curriculum and in the NSC practical exams.
How a Delphi program fits together
Delphi programs are event-driven: you design a form (a window) with components on it, and then write code that runs when an event happens — usually when the user clicks a button. In the IDE you will work with four main areas:
- Form Designer — where you drag components onto your form and arrange them.
- Object Inspector — where you change a component's properties (like Name, Caption and Text) and hook up its events.
- Code Editor — where you type your Object Pascal code.
- Tool Palette — the list of components you can add (TButton, TEdit, TLabel, TMemo …). Older Delphi versions at some schools call this the Component Palette — same thing.
Double-click a button on the form and Delphi creates an event handler for you — a procedure with a name like btnCalculateClick — and that is where your code goes.
Naming conventions (very important!)
South African IT classes use prefixes so that you can see at a glance what something is. Markers expect them, so make them a habit from day one:
| Component | Prefix | Example |
|---|---|---|
| Form | frm | frmQuiz |
| Button (TButton) | btn | btnCalculate |
| Edit box (TEdit) | edt | edtName |
| Label (TLabel) | lbl | lblAnswer |
| Memo (TMemo) | mem | memOutput |
| Panel (TPanel) | pnl | pnlHeader |
Variables get prefixes too: i for Integer (iCount), r for Real (rPrice), s for String (sName), c for Char (cGrade) and b for Boolean (bFound).
edtAge and instantly knowing "edit box holding an age" saves you minutes.Quick check before we write code:
Quick check
Question 1
You want to change a button's Caption from "Button1" to "Calculate". Where do you do that?
Answer
The Object Inspector — Properties like Name and Caption are changed in the Object Inspector (or in code, e.g. btnGo.Caption := 'Calculate').
Question 2
Which is the best name for an edit box where the user types their surname?
Answer
edtSurname — The edt prefix tells everyone it is a TEdit, and Surname says what it holds. Edit1 tells you nothing, and btn would mean a button.
Question 3
Delphi programs run code when the user clicks buttons or types. This style of programming is called…
Answer
event-driven programming — Code sits in event handlers and waits for events (like OnClick) to happen — event-driven.
Question 4
You double-click btnStart on the form. What does Delphi create in the Code Editor?
Answer
An event handler procedure named btnStartClick — Double-clicking a component creates its default event handler — for a button that is the OnClick handler, e.g. procedure TfrmMain.btnStartClick(Sender: TObject);