[fpc-pascal] assigning a local function to a var

Chris Cheney chris.cheney at tesco.net
Wed Jul 9 22:02:39 CEST 2008


> I'd like to store an address of a local function in a variable, and
> call that local function, but I don't know how to define a variable of
> type "local function". Here's the error I'm stuck on, with sample
> code: 

"One can assign the following values to a procedural type variable:
1. Nil, for both normal procedure pointers and method pointers.
2. A variable reference of a procedural type, i.e. another variable of 
the same type.
3. A global procedure or function address, with matching function or 
procedure header and calling
convention.
4. A method address."

[reference manual
ftp://ftp.freepascal.org/pub/fpc/docs-pdf/ref.pdf
page 38]

Note "A GLOBAL procedure or function ... "

This is for a reason - think what would happen if you were able to a 
local procedure to a global variable!

FWIW the same is true of Delphi.

HTH



More information about the fpc-pascal mailing list