User manual

210
mikoPascal PRO for PIC32
MikroElektronika
Records
A record (analogous to a structure in some languages) represents a heterogeneous set of elements. Each element is
called a eld. The declaration of the record type species a name and type for each eld. The syntax of a record type
declaration is
type recordTypeName = record
eldList1 : type1;
...
eldListn : typen;
end;
where recordTypeName is a valid identier, each type denotes a type, and each eldList is a valid identier or a
comma-delimited list of identiers. The scope of a eld identier is limited to the record in which it occurs, so you don’t
have to worry about naming conicts between eld identiers and other variables.
Note : In mikroPascal PRO for PIC32, you cannot use the 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 elds: 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 eld can be of previously dened record type. For example:
// Structure dening a circle:
type
TCircle = record
radius : real;
center : TDot;
end;
Accessing Fields
You can access the elds of a record by means of dot (.) as a direct eld selector. If we have declared variables
circle1 and circle2 of previously dened type TCircle:
var circle1, circle2 : TCircle;
we could access their individual elds like this: