Introduction to Delphi Grade 10

Delphi is a visual programming environment — you design the screen AND write the code. You drag components onto a form to build the interface, then write Pascal code to make it all work. This page covers the IDE layout, components, naming, events, and your first program.

The Delphi IDE — What You See When You Open It

When you open Delphi, this is what you will see. It might look overwhelming at first — but each area has one clear job:

Delphi 11 IDE in Design View
Delphi 11 — Design View (this is where you build the form your user will see)
Object Inspector
Object Inspector — set properties like Name, Caption, Color
Tool Palette
Tool Palette — drag components from here onto the form

Switching to Code View

Press F12 to toggle between the Design View (what you see above) and the Code View (where you type your Delphi code).

Delphi Code View
Code View — this is the Delphi code structure that is automatically created for you

The Delphi IDE Layout

The Integrated Development Environment (IDE) is where you write, design and run your programs. Think of it as your workshop — every tool you need is right there.

Delphi IDE MENU BAR File Edit View Project Run Component Tools Help STRUCTURE PANEL Form1 btnCalculate lblResult edtInput memOutput imgLogo FORM / DESIGN AREA Form1 TLabel — lblTitle TEdit — edtInput TButton TMemo — memOutput Press F12 to toggle Code View TOOL PALETTE Standard TLabel TButton TEdit Additional TMemo TImage TPanel Win32 TDateTimePicker Dialogs TOpenDialog OBJECT INSPECTOR btnCalculate : TButton Caption'Calculate' NamebtnCalculate EnabledTrue Font.Size10 Properties | Events CODE VIEW F12 1procedure TForm1.btnCalculateClick(Sender: TObject); 2begin 3 ShowMessage('Hello!'); 4end; ← Write your code between begin and end

Key IDE Panels

PanelPurpose
Menu BarTop menu — File, Edit, View, Project, Run, Tools etc.
Tool PaletteAll Delphi components grouped by category. Click a component, then click on the form to place it.
Object InspectorSets the initial properties and events of a selected component.
Structure PanelQuick reference showing all objects on the current form.
Form / Design AreaThe visual canvas — drag and drop components here to build the UI.
Code ViewWhere you write Pascal code. Toggle with F12.

Step-by-Step: Creating Your First Project

  1. File → New → Windows VCL Application — creates a blank Form (TForm).
  2. Place components by clicking them in the Tool Palette, then clicking on the form.
  3. Set properties in the Object Inspector (e.g. change a button's Caption).
  4. Double-click a button to go to Code View and write the event handler.
  5. File → Save All (Ctrl+Shift+S) — save in a NEW dedicated folder.
  6. Press F9 to compile and run.
Save in its own folder — always!

Each project must be saved in its own dedicated folder. Save the Unit file as FileName_u.pas and the Project file as FileName_p.dproj. Never mix two projects in one folder.

Visual Component Reference

Components are the building blocks placed on a form. Each is an object with properties and events. Here is what the most common ones look like:

Form1 TForm The window itself Your Label Here TLabel Displays text Click Me TButton Triggers code user types here TEdit Single-line input Line 1 Line 2 Line 3 TMemo Multi-line text [ image ] TImage Displays a picture RadioGroup Option A Option B Option C TRadioGroup Accept terms Subscribe TCheckBox Panel1 Groups components TPanel scroll down ... TListBox List of items

Naming Convention

Every component gets a prefix that indicates its type, followed by a meaningful name. This makes code readable.

PrefixComponent TypeExample
btnTButtonbtnCalculate
lblTLabellblResult
edtTEditedtName
memTMemomemOutput
imgTImageimgLogo
pnlTPanelpnlHeader
sedTScrolledEditsedNotes
cboTComboBoxcboGrade
lstTListBoxlstNames
rgpTRadioGrouprgpGender
chkTCheckBoxchkAgree
tmrTTimertmrClock

Event-Driven Programming

Delphi programs are event-driven — code only runs when something HAPPENS (an event), like pressing a button, typing in a box, or a timer ticking.

Vending Machine Analogy

Think of a vending machine. It just sits there doing nothing — until you push a button. That press is the event. The machine then dispenses the item — that is the event handler (your code). If no button is pressed, nothing happens. Delphi works exactly like this.

EventWhen it firesCommon use
OnClickUser clicks a button / componentCalculate, submit, navigate
OnChangeText in an edit box changesLive validation, update display
OnKeyPressA key is pressed while component has focusAccept only numbers
OnCreateForm loads / opensInitialise variables, load data
OnTimerTimer interval elapsesCountdown, clock display

How to Create an Event Handler

  1. In Design View, double-click a button to create its OnClick handler automatically.
  2. For other events, go to the Events tab in the Object Inspector and double-click next to the event name.
  3. Delphi creates a skeleton procedure. Write your code between begin and end.
  4. Never change the procedure header — only add code inside.
Delphi — Button Click Event
procedure TForm1.btnCalculateClick(Sender: TObject);
begin
  // Your code goes here
  ShowMessage('Button clicked!');
end;

ShowMessage and InputBox

ShowMessage displays a pop-up with a message. InputBox pops up a window asking the user to type something. Both are modal — the program pauses until the user responds.

Information i Hello world! OK ShowMessage('Hello world!') One message, one OK button. No return value. Name Enter your name: Alice OK Cancel InputBox('Name','Enter your name:','') Always returns a String — convert if needed
Delphi — ShowMessage
ShowMessage('Hello world!');
ShowMessage('Result: ' + IntToStr(iAnswer));
Delphi — InputBox (returns String, convert as needed)
// Returns a string
sName   := InputBox('Name', 'Enter your name:', '');

// Convert to integer
iNum    := StrToInt(InputBox('Number', 'Enter a number:', ''));

// Convert to real
rAmount := StrToFloat(InputBox('Amount', 'Enter amount:', ''));

// Get first character only
cClass  := InputBox('Class', 'Enter class:', '')[1];

Components — Properties

Properties control how a component looks and behaves. Set them in the Object Inspector or through code.

PropertyDescriptionExample Value
NameUnique identifier used in codebtnCalculate
CaptionText shown on labels, buttons, forms'Calculate'
TextText in a TEdit boxedtName.Text
HeightComponent height in pixels30
WidthComponent width in pixels150
Font.SizeText size14
Font.ColorText colour (note: Color not Colour)clRed
VisibleWhether component is shownTrue / False

Setting Properties in Code

Format: ComponentName.Property := Value;

Delphi
Form1.Height        := 500;
Button1.Caption     := 'Register';
Label1.Font.Color   := clGreen;
Shape1.Brush.Color  := clRed;
Shape1.Top          := 20;
Shape1.Left         := 20;

Methods

Methods are pre-written operations that perform tasks on components. Format: ComponentName.Method;

MethodEffect
Button1.Hide;Makes the button invisible
Button1.Show;Makes the button visible again
Edit1.SetFocus;Moves the cursor into the edit box
Memo1.Clear;Clears all text in the memo
Form1.Close;Closes the form / program
RichEdit1.Lines.Add('text');Adds a new line to a RichEdit or Memo

Syntax Rules

Syntax Errors

Every statement ends with a semicolon ;. Missing one causes a syntax error. There is never a semicolon before else. Begin/end pairs must always match.