SourceForge has been redesigned. Learn more.
Close

#15 Cannot change object field variables By Reference

open
5
2005-08-03
2005-08-03
No

It is not possible to change object field variables "by
reference".

procedure SetInt(var i: integer); // call by reference
begin
i := 55;
end;

// call from a class
type Test = class
F: integer;
constructor Create();
public
procedure SetInt2( var i: integer );
end;

constructor Test.Create();
begin
F := 20;

SetInt( F ); // public procedure
Print( IntToStr( F ) );
SetInt2( F ); // object procedure
Print( IntToStr( F ) );

SetInt2( F );
Print( IntToStr( F ) );
SetInt2( F );
Print( IntToStr( F ) );

// (* All Prints show the F never changes from 20 *)
end;

procedure Test.SetInt2( var i: integer );
begin
i := 75;
end;

var t: Test = Test.Create();

Discussion


Log in to post a comment.