In C you can use a pointer to a function as a parameter in another function like so:
Is this possible in pascal?Code:void MyFunction( void (*ParameterFunction)(ParameterFunctionsParameters) ) { }
In C you can use a pointer to a function as a parameter in another function like so:
Is this possible in pascal?Code:void MyFunction( void (*ParameterFunction)(ParameterFunctionsParameters) ) { }
I'm pretty sure you can do it in pascal considering you can do it in Simba scripts. Here is a commonly used example:
Simba Code:MMouse(x, y, RandomRange(-2, 2), RandomRange(-2, 2));
So it will use the return value of the RandomRange function for the pixel randomness of x and y. You just have to make sure that the function you are using as the parameter returns the data type needed.
orSimba Code:function TestFunc : string;
begin
result := 'test';
end;
procedure Test(Func : function : string);
begin
Writeln(Func());
end;
begin
Test(@TestFunc);
end.
Simba Code:function TestFunc : string;
begin
result := 'test';
end;
procedure Test(Func : string; Params : TVariantArray);
begin
writeln(CallProc('TestFunc', Params));
end;
begin
Test('TestFunc', []);
end.
Last edited by Sex; 04-22-2011 at 06:04 PM.
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl"A programmer is just a tool which converts caffeine into code"
If you would like to pass parameters!
Simba Code:type
TExFunc = function(s: string): boolean;
function test(test2: TExFunc): boolean;
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl"A programmer is just a tool which converts caffeine into code"
Yeah, was gonna just edit that in...but I still think it is nifty .
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl"A programmer is just a tool which converts caffeine into code"
There are currently 1 users browsing this thread. (0 members and 1 guests)