W
wooz
There is a class (just simple example):
Public class clsTest
public x as integer
public y as integer
End class
There is an object:
dim obj as new clsTest
obj.x=5
obj.y=6
Now i want to make copy of object obj. I don't want to set each atribut in
new object one by one, like this:
dim obj2 as new clsTest
obj2.x=obj.x
obj2.y=obj.y
and i don't want to write a copy constructor for class clsTest:, so i write
a simple function:
public function CopyObj(byval argSourceObj as clsTest,byref argDestObj as
clsTes)
argDestObj=argSourceObj
end function
CopyObj(obj,obj2)
Unfortunetly it doesn't work. "Obj" and "Obj2" point to the same object.
Inside of function "CopyObj" there should be a copy of "Obj" becouse it is
passed by value not by reference. What do i wrong ? Is it possible at all to
make quick and easy copy of some objects ? Example above is very simple but
i use much more complex objects, so i'm looking for smart way to copy
objects.
Public class clsTest
public x as integer
public y as integer
End class
There is an object:
dim obj as new clsTest
obj.x=5
obj.y=6
Now i want to make copy of object obj. I don't want to set each atribut in
new object one by one, like this:
dim obj2 as new clsTest
obj2.x=obj.x
obj2.y=obj.y
and i don't want to write a copy constructor for class clsTest:, so i write
a simple function:
public function CopyObj(byval argSourceObj as clsTest,byref argDestObj as
clsTes)
argDestObj=argSourceObj
end function
CopyObj(obj,obj2)
Unfortunetly it doesn't work. "Obj" and "Obj2" point to the same object.
Inside of function "CopyObj" there should be a copy of "Obj" becouse it is
passed by value not by reference. What do i wrong ? Is it possible at all to
make quick and easy copy of some objects ? Example above is very simple but
i use much more complex objects, so i'm looking for smart way to copy
objects.