HP Pascal/iX Programmer's Guide (31502-90023)
6- 5
mstat := single; {New does not make this assignment}
divorced := FALSE;
widowed := FALSE;
engaged := FALSE;
END;
new(person2,married);
WITH person2^ DO BEGIN
lname := 'Smith';
fname := 'Jane';
kids := 3;
mstat := married; {New does not make this assignment}
how_many_times := 1;
how_long_this_time := 9;
END;
new(person3);
END.
The new record variable person1^ has space for the fixed fields lname,
fname, kids, and mstat, and for the single variant fields divorced,
widowed, and engaged.
The new record variable person2^ has space for the same fixed fields, and
for the married variant fields how_many_times and how_long_this_time.
If the new variable is a record with nested variant fields, you can
specify a tag for each variant. If you do, you must specify them in the
order that they are declared, and you cannot leave gaps in the sequence.
Example 3
In this program, the declaration order of the tag fields is obviously t1,
t2 or t1, t3.
PROGRAM prog;
TYPE
r = RECORD
f1 : integer;
CASE t1 : (a,b) OF
a : (arec : RECORD
i : integer;
CASE t2 : (c,d) OF
c : (j : integer);
d : (k : real);
END {arec}
);
b : (brec : RECORD
CASE t3 : (e,f) OF
e : (l : real);
f : (m : char);
END {brec}
);
END; {r}
rptr = ^r;
VAR
v : rptr;
BEGIN
new(v);
new(v,a);
new(v,a,c);
new(v,a,d);
new(v,,d); {illegal -- must specify a}
new(v,d); {illegal -- must specify a}
new(v,b);
new(v,b,e);
new(v,e,b); {illegal -- tags are not in order of declaration}
new(v,b,f);