[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
WITH Record Expansion pp 81
Define: A With statements consists of the reserved word With
followed by a list of record variables separated by commas,
followed by the reserved word Do and finally a statement.
Purpose: With 'opens up' a record so that the field identifiers may
be used as simple variable identifiers.
Notes: The use of records does sometimes result in lengthy statements.
It is much easier to access record fields as if they were simple
variables.
----------------------------------------------------------------------------
Usage:
TYPE
Name = Record
FamilyName : String [32];
GivenNames : Array [1..4] of String [16];
End;
Rate = Record
Normal : Integer;
Overtime : Integer;
Nights : Integer;
Weekend : Integer;
End;
Date = Record
Day : 1..31;
Month : (Jan,Feb,Mar,Apr,May,Jun,
Jul,Aug,Sep,Oct,Nov,Dec);
Year : 1900..1999;
End;
Person = Record
ID : Name;
Time : Date;
End;
Wages = Record
Individual : Person;
Cost : Rate;
End;
VAR
Salary : Wages;
Fee : Wages;
BEGIN
Salary := Fee;
Salary.Cost.Overtime := 950;
Salary.Individual.Time := Fee.Individual.Time;
Salary.Individual.ID.FamilyName := 'Smith';
{ Expand Wages record }
With Salary Do
Begin
Cost.Overtime := 950;
Individual.ID.FamilyName := 'Smith';
End;
{ Expand Wages/Person/Name/Date records }
With Salary, Individual, ID, Time do
Begin
FamilyName := 'Smith';
GivenNames[1] := 'Billy';
GivenNames[2] := 'Joe';
GivenNames[3] := 'Jim';
GivenNames[4] := 'Bob';
Day := 4;
Month := Nov;
Year := 1950;
End;
END.
Salary { Record of Wages }
Wages { Record of Individual/Cost }
Individual { Record of Person }
Person { Record of ID/Time }
ID { Record of Name }
Name { Record of FamilyName/GivenNames }
FamilyName { Field of Name record }
GivenName { Field of Name record }
Time { Record of Date }
Date { Record of Day/Month/Year }
Day { Field of Date }
Month { Field of Date }
Year { Field of Date }
Cost { Record of Rate }
Rate { Record of Normal/Overtime/Nights/Weekend }
Normal { Field of Rate }
Overtime { Field of Rate }
Nights { Field of Rate }
Weekend { Field of Rate }
See Also:
Record
Variant
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson