Quick start manual
Data types, variables, and constants
5-23
Structured types
To make the assignment work, declare the variables as
var Int1, Int2: array[1..10] of Integer;
or
type IntArray = array[1..10] of Integer;
var
Int1: IntArray;
Int2: IntArray;
Records
A record (analogous to a structure in some languages) represents a heterogeneous set
of elements. Each element is called a field; the declaration of a record type specifies a
name and type for each field. The syntax of a record type declaration is
type recordTypeName = record
fieldList
1
: type
1
;
ƒ
fieldList
n
: type
n
;
end
where recordTypeName is a valid identifier, each type denotes a type, and each fieldList
is a valid identifier or a comma-delimited list of identifiers. The final semicolon is
optional.
For example, the following declaration creates a record type called TDateRec.
type
TDateRec = record
Year: Integer;
Month: (Jan, Feb, Mar, Apr, May, Jun,
Jul, Aug, Sep, Oct, Nov, Dec);
Day: 1..31;
end;
Each TDateRec contains three fields: an integer value called Year, a value of an
enumerated type called Month, and another integer between 1 and 31 called Day. The
identifiers Year, Month, and Day are the field designators for TDateRec, and they behave
like variables. The TDateRec type declaration, however, does not allocate any
memory for the Year, Month, and Day fields; memory is allocated when you
instantiate the record, like this:
var Record1, Record2: TDateRec;
This variable declaration creates two instances of TDateRec, called Record1 and
Record2.
You can access the fields of a record by qualifying the field designators with the
record’s name:
Record1.Year := 1904;
Record1.Month := Jun;
Record1.Day := 16;