[fpc-pascal] assigning a local function to a var
David Emerson
dle3ab at angelbase.com
Wed Jul 9 18:31:14 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:
Error: Incompatible types:
got "<address of local function(AnsiString):Boolean;Register>"
expected "<procedure variable type of
function(AnsiString):Boolean;Register>"
procedure test;
function func_a (pass_str : ansistring) : boolean;
begin
writeln (pass_str, 'A');
func_a := true;
end;
function func_b (pass_str : ansistring) : boolean;
begin
writeln (pass_str, 'B');
func_b := false;
end;
var
// what should this be??
my_func : function (pass_str : ansistring) : boolean;
begin
my_func := @func_a;
my_func('hello, ');
end;
Thanks!
~David.
More information about the fpc-pascal
mailing list