User manual
206
mikoPascal PRO for PIC32
MikroElektronika
program Example;
type TMyFunctionType = function (param1, param2: byte; param3: word) : word; // First,
dene the procedural type
var MyPtr: ^TMyFunctionType; // This is a pointer to previously dened type
Sample: word;
function Func1(p1, p2: byte; p3: word): word; // Now, dene few functions
which will be pointed to. Make sure that parameters match the type denition
begin
result := p1 and p2 or p3; // return something
end;
function Func2(abc: byte; def: byte; ghi: word): word; // Another function of the
same kind. Make sure that parameters match the type denition
begin
result := abc * def + ghi; // return something
end;
function Func3(rst, yellow: byte; monday: word): word; // Yet another function. Make
sure that parameters match the type denition
begin
result := monday - yellow - rst; // return something
end;
// main program:
begin
MyPtr := @Func1; // MyPtr now points to Func1
Sample := MyPtr^(1, 2, 3); // Perform function call via pointer, call Func1,
the return value is 3
MyPtr := @Func2; // MyPtr now points to Func2
Sample := MyPtr^(1, 2, 3); // Perform function call via pointer, call Func2,
the return value is 5
MyPtr := @Func3; // MyPtr now points to Func3
Sample := MyPtr^(1, 2, 3); // Perform function call via pointer, call Func3,
the return value is 0
end.
Therefore, when declaring a pointer within constant declaration block, const qualier refers to pointed object, not to
pointer itself.