SRL Archive - OSR Help

Functions with mutliple results


HT BaaFly

2012-01-03 15:14:50

Is it possible to have a function return more than one result consisting of different variables? and if so, how?
E.g. Have a function return both a boolean and an integer

Shuttleu

2012-01-03 15:17:34

sure, just with it in the header


function something(var i: Integer): Boolean;
it will return a boolean as the result
and it will return a integer in i

~shut

Troll

2012-01-03 15:19:05

Yes in create a type and make it return that,
Type
boolInt = record
bool = Boolean;
Number = Integer;

and then do Func Name:boolInt;
and use it by
Function Derp():boolInt;
Her := Derp();

then Her.bool = true/false
and Her.Number will be a interger

E: Look at shut who ninja'd me it is so much simpler i forgot about it :p mine is long winded

HT BaaFly

2012-01-03 15:21:17

From: Shuttleu
sure, just with it in the header


function something(var i: Integer): Boolean;
it will return a boolean as the result
and it will return a integer in i

~shut


ah, I slightly get it but I've got a few more questions, if you don't mind :)

Once the function runs how would the results be set e.g.:


function something(var i: Integer): Boolean;
begin
if something then
result := true //boolean
result := 44
end;

would that set both variables or am i doing it wrong?

Edit: @Troll: i'm gonna try it now, brb

Shuttleu

2012-01-03 15:23:06

From: HT BaaFly
ah, I slightly get it but I've got a few more questions, if you don't mind :)

Once the function runs how would the results be set e.g.:


function something(var i: Integer): Boolean;
begin
if something then
result := true //boolean
result := 44
end;

would that set both variables or am i doing it wrong?


it would be like so

function something(var i: Integer): Boolean;
begin
if something then
result := true //boolean
i := 44
end;

~shut

HT BaaFly

2012-01-03 15:25:30

From: Shuttleu
it would be like so

function something(var i: Integer): Boolean;
begin
if something then
result := true //boolean
i := 44
end;

~shut


so i works like a global variable?

another point, are things between the brackets always input and not outputs?

function something(var i: Integer): Boolean;

Shuttleu

2012-01-03 15:27:10

it it has var before it then it is a input and a output

but if it does not then it is just a input

~shut

HT BaaFly

2012-01-03 15:28:25

ok thanks a lot man I love you

+ripped everyone that helped

Brandon

2012-01-03 15:32:10

Don't rep me.. only stating what troll posted.


program new;

type
return = record
Int: Integer;
bool: Boolean;
end;

Function Returnstwo(I: integer): return;
begin
Result.bool:= true;
Result.Int:= 3;
end;

HT BaaFly

2012-01-03 15:39:25

thanks a lot for making it clearer :) just one question about troll's method: outside of the function, how would you set the result
e.g.:

boolean := Returnstwo;
int := Returnstwo;

simple as that or what?

Kasi

2012-01-03 15:48:19


Var
I : Integer;
B : Boolean;

I := Returnstwo.Int
B := Returnstwo.bool

HT BaaFly

2012-01-03 15:50:18

much much clearer now thanks to everyone :)