HP Pascal/iX Programmer's Guide (31502-90023)
6- 9
new(v4);
p(v4^);
new(v4);
r(v4); {s (within r) disposes r's actual parameter v4,
which is illegal}
new(v4);
new(v5);
WITH v4^,v5^ DO BEGIN
f1 := 1;
f2 := 2;
f3 := 3;
q; {illegal -- q disposes v4 while the WITH statement
whose record variable list it is in
is active}
dispose(v5); {illegal -- v5 is in the record variable list
of an active WITH statement}
END;
END.
If you specify tags when you allocate a variable with
new
, you must
specify the same tags in the same order when you deallocate the variable
with
dispose
.
Example 2
PROGRAM prog;
TYPE
rec = RECORD
CASE t1 : (a,b) OF
a : (a1,a2 : integer);
b : (b1 : RECORD
CASE t2 : (c,d) OF
c : (c1 : char);
d : (d1,d2 : real);
END
);
END;
recptr = ^rec;
VAR
v1,v2,v3,v4,v5 : recptr;
BEGIN
new(v1);
new(v2,a);
new(v3,b);
new(v4,b,c);
new(v5,b,d);
dispose(v1);
dispose(v2,a);
dispose(v3,b);
dispose(v4,b,c);
dispose(v5,b,d);
new(v1);
new(v2,a);
new(v3,b);
new(v4,b,c);
new(v5,b,d);
dispose(v1,a); {illegal -- a not specified on new}
dispose(v2,b); {illegal -- b not specified on new}
dispose(v3); {illegal -- b specified on new, but not here}
dispose(v4,b); {illegal -- c specified on new, but not here}
dispose(v5,d,b); {illegal -- b and d are in the wrong order}
END.