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
TShelter = recorddeclares the fieldsName: string;andBeds: Integer;.Corrour.NameandCorrour.Bedsare assigned through the dot.Roomy(const S: TShelter)receives the whole record and testsS.Beds >= 12.
Keywords and builtins used here
BooleanIntegerResultRoomyWriteLnbeginconstendfunctionprogramrecordstringtypevar
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.
Step 3 of 3 in Arrays & records, step 15 of 27 in Language basics.