A record is a sequence of named variables, called the fields of
the record. Different fields can have different types. The name and type of
each field is statically determined by the record's type. The expression
r.f
designates the field named f
in the record r
.
A record type declaration has the form:
TYPE T = RECORD FieldList ENDwhere
FieldList
is a list of field declarations, each of which has the
form:
fieldName: Type := defaultwhere
fieldName
is an identifier, Type
is any non-empty type
other than an open array type, and default
is a constant expression.
The field names must be distinct. A record is a member of T
if it has
fields with the given names and types, in the given order, and no other
fields. Empty records are allowed.
The constant default
is a default value used when a record is
constructed or allocated. Either ``:= default
'' or ``: Type
''
can be omitted, but not both. If Type
is omitted, it is taken to be
the type of default
. If both are present, the value of default
must be a member of Type
.
When a series of fields shares the same type and default, any fieldName
can be a list of identifiers separated by commas. Such a list is shorthand
for a list in which the type and default are repeated for each identifier.
That is:
f_1, ..., f_m: Type := defaultis shorthand for:
f_1: Type := default; ...; f_m: Type := defaultThis shorthand is eliminated from the expanded definition of the type. The default values are included.
Examples of record types:
TYPE Time = RECORD seconds: INTEGER; milliseconds: [0..999] END; Alignment = {Left, Center, Right}; TextWindowStyle = RECORD align := Alignment.Center; font := Font.Default; foreground := Color.Black; background := Color.White; margin, border := 2 END
m3-support@elego.de