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 the record type specifies a name and type for each field. The syntax of a record type declaration is
type recordTypeName = record fieldList1 : type1; ... fieldListn : typen; 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 scope of a field identifier is limited to the record in which it occurs, so you don’t have to worry about naming conflicts between field identifiers and other variables.

record
construction directly in variable declarations, i.e. without type
.
For example, the following declaration creates a record type called TDot
:
type TDot = record x, y : real; end;
Each TDot
contains two fields: x
and y
coordinates. Memory is allocated when you declare the record, like this:
var m, n: TDot;
This variable declaration creates two instances of TDot
, called m
and n
.
A field can be of previously defined record type. For example:
// Structure defining a circle: type TCircle = record radius : real; center : TDot; end;
Accessing Fields
You can access the fields of a record by means of dot (.
) as a direct field selector. If we have declared variables circle1
and circle2
of previously defined type TCircle
:
var circle1, circle2 : TCircle;
we could access their individual fields like this:
circle1.radius := 3.7; circle1.center.x := 0; circle1.center.y := 0;
Accessing the fields is possible via the with
statement as well.
You can also commit assignments between complex variables, if they are of the same type:
circle2 := circle1; // This will copy values of all fields
What do you think about this topic ? Send us feedback!