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 Delphi code to make it all work. This page covers the IDE layout, components, naming, events, and your first program.

T1Term 1 · Introduction to the Delphi IDE

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

An Integrated Development Environment (IDE) is a software application that combines the tools a programmer needs — a code editor, a compiler, and a debugger — into a single interface, so you can design, write, test and run a program without switching between separate tools.

Think of it this way

Think of the IDE as your workshop — every tool you need (editor, compiler, debugger) is laid out and ready to use, all in one place.

Why Delphi Counts as "RAD" Software

RAD stands for Rapid Application Development. The label applies to Delphi because most of the visual work is already done for you: instead of writing code to draw a button or a text box pixel by pixel, you drag a ready-made component from the Tool Palette onto the form. Skipping that low-level drawing work is what lets a small classroom project turn into a working app within a single lesson.

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 Panel (Object TreeView)Quick reference showing all objects on the current form, displayed in a hierarchical (tree) view.
Form / Design AreaThe visual canvas — drag and drop components here to build the UI.
Code ViewWhere you write Delphi code. Toggle with F12.

Objects, Classes & Components

Delphi is an Object-Oriented Programming (OOP) language, so almost everything you place on a form is an object. To talk about objects precisely, three related terms are used:

TermMeaning
ClassThe plan or blueprint for an object — for example TButton is the class that defines what every button can look like and do. Class names always start with a capital T.
ObjectAn instance of a class — an actual button, label or form that exists in your program, e.g. btnCalculate is an object (instantiation) of the class TButton.
ComponentA particular type of object that can be placed on a form to build a user-friendly, interactive interface (e.g. a Button, Label or Edit).
Blueprint analogy

Before a house is built, an architect draws up plans — the class. Many houses can then be built from the same plan — each one is an object (an instantiation of the class). TButton is the plan; btnCalculate and btnCancel are two different objects built from that same plan.

Every object has:

Basic Format of Statements

An assignment statement stores a value in a property or variable using the assignment operator :=. We use code in Delphi to assign values to properties of components in the following format:

Delphi — general format
Component.Property := Value;

All the properties a component has can be seen in the Object Inspector when that component is selected — the same properties you set visually at design time can also be set in code.

Two rules every statement follows
  • Always assign TO the component/property on the left side of := — never the other way round.
  • Every statement ends with a semicolon ;
Delphi — examples
Form1.Height := 500;
Form1.Width := 700;
Button1.Caption := 'Register';
Shape1.Top := 20;
Shape1.Left := 20;

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.dpr. Never mix two projects in one folder.

The Files Delphi Creates

Delphi creates several files for every program, but you only ever need to save two of them yourself — Delphi regenerates the rest automatically when you run the program.

FileExtensionContainsSave it yourself?
Unit file.pasThe Delphi code you write (event handlers, class definition)Yes
Project file.dprInformation that ties the units of a project togetherYes
Form file.dfmThe visual layout of the form and its componentsNo — saved automatically with the Unit
Transferring a project to another computer

If you need to copy a project to another computer, copy the .dpr, .dfm and .pas files — Delphi will recreate every other file the next time you run the program.

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
sedTSpinEditsedNotes
cboTComboBoxcboGrade
lstTListBoxlstNames
rgpTRadioGrouprgpGender
chkTCheckBoxchkAgree
tmrTTimertmrClock

Accelerator (Hot) Keys

Placing an & in front of a letter in a component's Caption underlines that letter and turns it into a keyboard shortcut. Pressing Alt + that letter clicks the component without using the mouse.

Delphi — example
btnRed.Caption := '&Red';   // underlines the R — press Alt+R to click the button

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

More Properties in Code

The same Component.Property := Value; format works for every property, including nested ones like Font.Color:

Delphi
Label1.Font.Color   := clGreen;
Shape1.Brush.Color  := clRed;

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

Forgetting the closing semicolon ; on a statement causes a syntax error. There is never a semicolon before else. Begin/end pairs must always match.