SRL Archive - OSR Help

Function Return two vals?


sm0k3

2011-04-02 16:33:58

Can a Function return two values ..

for a auto color function i need to reurn turn the x and y's for the found color ..

i've tried puting return:= MSCX,MSCY but i dosent work ..

i need it to retturn something like ..124,321
X Y

mormonman

2011-04-02 16:36:05

function a: TPoint;
begin
Result.x := x;
Result.y := y;
end;

Troll

2011-04-02 16:42:03

From: mormonman
function a: TPoint;
begin
Result.x := x;
Result.y := y;
end;


Then to use the X and Y, use .x and .y of the result you set it too E.x.

MyPoints := a;
a.x is x
a.y is y

NCDS

2011-04-02 16:42:37

From: mormonman
function a: TPoint;
begin
Result.x := x;
Result.y := y;
end;


or Result := Point(x, y); if your looking to save some lines. ;)

Sex

2011-04-02 17:30:25

Or for more.
function Func : array [0..1] of integer;
begin
result := TIntegerArray([2, 3]);
end;
Etc.

But for 2 value results just use the TPoint method mentioned above.

nielsie95

2011-04-02 17:35:13


function test(const varIn: Integer; out Result1: string): Integer;
begin
end;

Would be the formal way to return multiple variables :)

Sex

2011-04-02 17:45:43

Isn't out like almost the same as var?

Dgby714

2011-04-02 17:57:44

From: Sex
Isn't out like almost the same as var?


Using const it should already be initialized and have a value. (In)
Using var it should already be initialized and have a value. (In and Out)
Using out it shouldn't. (Out)
Using nothing is the same as const. (I think)