SRL Archive - Help and Support

Returning values


danrox2004

2007-03-21 03:54:58

Say I had a function which changed the value of x or y to something, how would i get the global x and y to change to it… here is a simple example:
program New;
var
x, y: integer;

function CCXX(x, y: integer): Boolean;
begin
x := 10;
y := 20;
Result := True;
end;

begin
CCXX(x, y)
Writeln(IntToStr(x) + ', ' + IntToStr(y));
end.

this writes in 0, 0 instead of 10, 20

Edit: Found it, for people intrested add var inside the function thing

WT-Fakawi

2007-03-21 06:35:00

Try it like this. By putting var before the variable declaration, you are telling Delphi you are expecting values from this variables. Thus generating output.

program New;
var
x, y: integer;

procedure CCXX(var x, y: integer):
begin
x := 10;
y := 20;
end;

begin
CCXX(x, y)
Writeln(IntToStr(x) + ', ' + IntToStr(y));
end.

danrox2004

2007-03-21 07:39:28

Yeah thanks alot lol.. I needed it for my world changer