SRL Archive - Help and Support

Function as an argument?


vilon

2007-12-13 09:06:01

Hi, was thinking about how you could call a procedure/function in some way, by specifing the name as an argument in a function. It could look like this:

program FunctionAsArgument;

function Done: Boolean;
begin
Result := True;
end;

function WaitFor(NAME): Boolean; // NAME would be the name of the function to call
begin
repeat
Wait(100);
until(NAME); // Waits until the specified function returns true
end;

begin
WaitFor(Done);
end.

Do anyone know if this is possible? And if it is, how?

Markus

2007-12-13 09:54:39

Yea, it's possible: http://www.villavu.com/forum/showthread.php?t=22488

R0b0t1

2007-12-13 20:01:11


program New;

type
TestProc = function(s: string): String;

function WaitFor(FunctionTo: TestProc; S: String): String;
begin
Result:= FunctionTo(S);
end;

begin
WaitFor(@PutFunctionTitleHere, 'Some string'); //Must include '@'
end.