| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- program t78_setfield;
- { t78 -- a SET field of a record: assignment and membership.
- CALC.INC:161 is the first statement inside `with Sheet[I,J] do':
- CellStatus := [Txt];
- CellStatus is `set of Attributes' (0..5, so ONE byte), NOT the default
- 32-byte `set of Char' that an untyped constructor becomes. The target
- supplies the base and size; the constructor's bytes are known at compile
- time and are stored at symbol+boff (a constant-index element) or through DI
- (a run-time-indexed one).
- `in' is the observation: a CODE-resident set (literal or typed constant)
- still folds at compile time, while a set FIELD is tested at run time by
- loading its byte and masking the element's bit. }
- type
- Attr = (Constant, Formula, Txt, OverWritten, Locked, Calculated);
- Cell = record
- Status : set of Attr;
- N : integer;
- end;
- var
- sh : array [1..2, 1..3] of Cell;
- begin
- with sh[1,1] do
- begin
- Status := [Txt];
- N := 5
- end;
- with sh[1,1] do
- if Txt in Status then writeln ('txt') else writeln ('no-txt');
- with sh[1,1] do
- if Locked in Status then writeln ('locked') else writeln ('not-locked');
- (* N sits immediately after the one-byte Status. Set it FIRST, then the
- set: a store that used the default 32-byte length would run over N and
- zero it. *)
- sh[2,3].N := 7;
- sh[2,3].Status := [Locked, Calculated];
- if Locked in sh[2,3].Status then writeln ('l2') else writeln ('nl2');
- if Txt in sh[2,3].Status then writeln ('t2') else writeln ('nt2');
- (* the fields after the set were not clobbered *)
- writeln (sh[1,1].N);
- writeln (sh[2,3].N)
- end.
|