Passing objects to functions |
|
I am having some trouble passing an Object to a function. The Object is quite complex: It has loads of Properties, subobjects, sub-sub Object, and lists of Objects. Inside the function, I do this:
Function SomeFunction(Origin: ComplexObject): ComplexObject;
var
NewObj: ComplexObject;
begin
If Origin = nil Then
Begin
NewObj:= ComplexObject.Create;
End
Else
NewObj:= Origin;
End;
// Edit Properties of NewObj....
Result:= NewObj;
end;
Now, any Properties i changed on NewObj is reflected to the Origin Object i passed in. So after this function, when I want to see if some of the Properties have ACTUALLY changed and i compare NewObj to Origin, they are always Equal, because Origin has been updated aswell. How can I avoid this, and get a result as I would With VB .Nets ByVal?
|
Re: Passing objects to functions |
|