User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
201
Example:
This example shows how to declare a function which returns a complex type.
program Example;
type TCircle = record // Record
CenterX, CenterY: word;
Radius: byte;
end;
var MyCircle: TCircle; // Global variable
function DeneCircle(x, y: word; r: byte): TCircle; // DeneCircle function returns a
Record
begin
result.CenterX := x;
result.CenterY := y;
result.Radius := r;
end;
begin
MyCircle := DeneCircle(100, 200, 30); // Get a Record via function call
MyCircle.CenterX := DeneCircle(100, 200, 30).CenterX + 20; // Access a Record eld
via function call
// |-----------------------| |-----|
// | |
// Function returns TCircle Access to one eld of TCircle
end.
Forward declaration
A function can be declared without having it followed by it’s implementation, by having it followed by the forward
procedure. The effective implementation of that function must follow later in the unit. The function can be used after a
forward declaration as if it had been implemented already. The following is an example of a forward declaration:
program Volume;
var Volume : word;
function First(a, b : word) : word; forward;
function Second(c : word) : word;
var tmp : word;
begin
tmp := First(2, 3);
result := tmp * c;
end;
function First(a, b : word) : word;
begin