SRL Archive - OSR Help

array of functions


wantonman

2012-08-08 19:54:25

may it be that it may but what is an array of functions called in the gi world? lol
scientific speaking XDIMENTIONALARRAY? haha

wantonman

2012-08-08 20:16:05

thats super helpful hey how can i make a function return a function in simba ??

Brandon

2012-08-08 20:40:40

There is always a way to do things =]. Think outside the box and the solution would be:


{$I SRL/SRL.Simba}

Function Meh: Boolean;
begin
writeln('Meh function called');
result := True;
end;

Function Bleh: Boolean;
begin
writeln('Bleh function called');
Result := Meh;
end;


Function Foo: Boolean;
begin
writeln('Foo function called');
Result := False;
end;

var
I: Integer;
Parameters: TVariantArray;
ArrayOfFuncs: TStringArray;
ArrayOfResult: TVariantArray;

begin
ArrayOfFuncs := ['Foo', 'Bleh', 'Meh'];
SetLength(ArrayOfResult, Length(ArrayOfFuncs));

For I := 0 To High(ArrayOfFuncs) Do
begin
ArrayOfResult[I] := CallProc(ArrayOfFuncs[I], Parameters);
end;
end.

m3gaman3g3nd

2012-08-08 20:54:47

humans vs animals

thats large!

CynicRus

2012-08-09 06:26:59

There is another version:

type TFunc = function (x,y: integer):integer;
type TFuncArray = array of TFunc;

function Plus(x,y: integer): integer;
begin
result:=x+y;
end;

function minus(x,y: integer): integer;
begin
result:=x-y;
end;
var
f: TFuncArray;
res:integer;
i: integer;
x,y: integer;
begin
SetLength(f,2);
x:=9;
y:=5;
F[0]:=@plus;
F[1]:=@minus;
for I:=0 to 1 do
begin
res:= f[i](x,y);
WriteLn(ToStr(res));
end;
end.

Output:

Compiled successfully in 15 ms.
14
4
Successfully executed.