On 23.07.2011 15:28, Benoît Minisini wrote:
>> Question:
>>
>> Assume I have an instance of class myclass dimed as 'myclass1'
>> and I want to clone all the data to NEW myclass2
>>
>> The syntax may be something like:
>>
>> myclass2 = NEW myclass   'create instance
>> myclass2.clone(myclass1) 'clone/copy
>>
>> I do realize that:
>> myclass2 = myclass2   only assigns a second pointer to the same single
>> object
>>
>>
>> I am assuming that there is no copy/clone of an instance to another
>> to make an exact replica copy, not just pointers to objects
>>
>> In the mean time, I'll start writing a copy/clone sub
>>
>> ??
>> -Fernando
>>
> Doing a deep copy in a standard way is impossible, so you have to implement
> your Clone() or Copy() method yourself.
>
> Regards,
>
i wrote this one some time ago, but don't know if it is well designed, i 
discarded the idea for some reason:
(on a form with TextBox1 and Button1 existing, copies the textbox and 
moves it just below the original one)

Public Sub Button1_Click()

   Dim hT As New TextBox(Me)

   Clone(hT, TextBox1)
   hT.Y += hT.Height

End

Public Sub Clone(hBuf As Object, hSource As Object)

   Dim sSym As String

   For Each sSym In Object.Class(hSource).Symbols 'get all symbols of a 
class
     If Object.Class(hSource)[sSym].Kind = Class.Property Then 'copy 
properties only
       Try Object.SetProperty(hBuf, sSym, Object.GetProperty(hSource, 
sSym)) 'try is for read-only properties in destintion object
     Endif
   Next

End

is that an acceptable solution?

regards,
tobi

------------------------------------------------------------------------------
Storage Efficiency Calculator
This modeling tool is based on patent-pending intellectual property that
has been used successfully in hundreds of IBM storage optimization engage-
ments, worldwide.  Store less, Store more with what you own, Move data to 
the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to