LearnStanmorephysics

Grade 10 · Delphi Foundations

Variables & data types

Grade 10 · Data & calculations · Lesson and coding task · about 12 minutes

Open this task in the Delphi workspace →

A variable is a named space in memory that holds one value. Before you use a variable in Delphi you must declare it in a var section, choosing a data type:

TypeHoldsPrefixExample value
Integerwhole numbersi16
Realdecimal numbersr1.62
Stringtexts'Amahle'
Charone characterc'A'
BooleanTrue / FalsebTrue
var
  sName : String;
  iAge : Integer;
  rHeight : Real;
begin
  sName := 'Amahle';   // := means "becomes"
  iAge := 16;
  rHeight := 1.62;

The := is the assignment operator — "sName becomes Amahle". A single = is only used for comparing.

Joining text and numbers

A memo line must be a String. To include a number you must convert it first:

memOutput.Lines.Add('Age: ' + IntToStr(iAge));
memOutput.Lines.Add('Height: ' + FloatToStr(rHeight) + ' m');
Exam tip. Forgetting IntToStr / FloatToStr when joining a number to text is one of the most common errors markers see. Delphi will refuse to compile it — so will we.

What you will do

Hints
  1. The var section goes between the procedure header and begin. Each declaration looks like name : Type;
  2. Assignment uses := , e.g. iAge := 16;
  3. To join a number into the text use IntToStr(iAge) and FloatToStr(rHeight). Note the space in ' m'.
Model solution
procedure TfrmProfile.btnShowClick(Sender: TObject);
var
  sName : String;
  iAge : Integer;
  rHeight : Real;
begin
  sName := 'Amahle';
  iAge := 16;
  rHeight := 1.62;
  memOutput.Lines.Add('Name: ' + sName);
  memOutput.Lines.Add('Age: ' + IntToStr(iAge));
  memOutput.Lines.Add('Height: ' + FloatToStr(rHeight) + ' m');
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.