Click to See Complete Forum and Search --> : copy a class


richardlctan
August 22nd, 2001, 04:18 AM
If I have 2 declarations of class object
DIM Cls as ADefinedClass
DIM ClsOld as ADefinedClass

SET Cls =new ADefinedClass
CLS.ID ="ABC"
SET ClsOld =Cls

' ------1 at this point ,ClsOld.id='ABC"
CLS.ID="CCC"
' ------2 at this point ,ClsOld.id='CCC"


Question:--
How I programme the code if I want the ClsOld to have a copy of old cls ,one that its .ID will not changed whenever Cls Changed.
It means that at point --2, I want the ClsOld.ID to remain as "ABC"

berta
August 22nd, 2001, 04:55 AM
SET ClsOld =Cls -> now ClsOld e Cls are set to the same object. To make a copy of a class U must for example add a method in ADefinedClass.

public function Clone() as ADefinedClass
dim newc as ADefinedClass
newc.id=me.id
set Clone = newc
end function

DIM Cls as ADefinedClass
DIM ClsOld as ADefinedClass

SET Cls =new ADefinedClass
CLS.ID ="ABC"
SET ClsOld =Cls.clone

' ------1 at this point ,ClsOld.id='ABC"
CLS.ID="CCC"
' ------2 at this point ,ClsOld.id='ABC"