[Gambas-user] How to clone an object?

Benoît Minisini g4mba5 at gmail.com
Fri Apr 24 03:19:47 CEST 2020


Le 24/04/2020 à 00:19, martin p cristia a écrit :
> 
> I want a clone an object I dont know what Class it is.
> 
> Public c1 as New Clase1                    ' These classes may have 
> arrays of other classes Object[]
> Public c2 as New Clase2                   ' All diffent
> Public c3 as New Clase3
> Public c4 as New Clase4
> 
> 
> ' at this point we don't know
> Public Function ClonMe(original as Object) as Object
> 
> ' a New object of the same kind with all variables/properties and 
> constants with the same values
> ?????
> 
> End
> 
> 
> 

You have to write the clone method for each class yourself.

Then, if all the classes you want to clone have a common ancestor, then 
declare the Clone() method inside. If they do not have a common 
ancestor, then you will have to use an anonymous reference to call the 
Clone method().

Regards,

-- 
Benoît Minisini


More information about the User mailing list