typestar

Records in Delphi

A TShelter record pairs a name with a bed count and travels whole into a function.

program RecordsBasics;
type
  TShelter = record        // a record groups named fields into one value
    Name: string;
    Beds: Integer;
  end;

function Roomy(const S: TShelter): Boolean;
begin
  Result := S.Beds >= 12;  // fields are reached through the dot
end;

var
  Corrour: TShelter;
begin
  Corrour.Name := 'Corrour Bothy';
  Corrour.Beds := 14;
  WriteLn(Corrour.Name, ' roomy: ', Roomy(Corrour));
end.

How it works

  1. TShelter = record declares the fields Name: string; and Beds: Integer;.
  2. Corrour.Name and Corrour.Beds are assigned through the dot.
  3. Roomy(const S: TShelter) receives the whole record and tests S.Beds >= 12.

Keywords and builtins used here

The run, in numbers

Lines
19
Characters to type
391
Tokens
82
Three-star pace
75 tpm

At the three-star pace of 75 tokens a minute, this run takes about 66 seconds.

Type this snippet

Step 3 of 3 in Arrays & records, step 15 of 27 in Language basics.

← Previous Next →

Records in other languages