HP Pascal/iX Reference Manual (31502-90022)

3- 19
Variant Part
In the
variant part
, the reserved word CASE introduces an optional
tag
field
identifier and a required
ordinal type identifier
. The reserved
word OF precedes a list of case constants and alternative field lists.
Case constants
must be compatible with the
tag
. See "Type Compatibility"
in this chapter for more information. Several case constants may be
associated with a single field list. The various constants appear
separated by commas. Subranges are also legal case constants in HP
Pascal. The empty field list may be used to indicate that a variant
doesn't exist. This is illustrated in the example in this section. HP
Pascal does not require that all possible tag values be specified.
The OTHERWISE construction may not be used in the variant part of the
field list. OTHERWISE is only legal in CASE statements.
Variant parts allow variables of the same record type to exhibit
structures that differ in the number and type of their component parts.
If a record has
multiple variants
, when a value is assigned to the tag
field, any fields associated with a previous variant cease to exist, and
the new variant's fields become active with undefined values. If there
is no tag field when a value is assigned to a field of any particular
variant, any fields associated with another variant cease to exist, and
the new variant fields become active with undefined values. An error
results when a reference is made to a field of a variant other than the
current variant. A field of a record is accessed using the appropriate
field selector.
Syntax
Variant_part: