[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Object copy function question
[Thread Prev] | [Thread Next]
- Subject: Re: Object copy function question
- From: Bruce Steers <bsteers4@xxxxxxxxx>
- Date: Thu, 5 Sep 2024 23:13:08 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
A method like CopyData or CopyNew or CopyContents or some other relevant word that copies an array contents as an actual copy without referencing would be awesome. The Word Copy kinda misleads to think you will get a true copy of the data instead of references. I've had to recursively copy arrays within arrays in some code to overcome the referencing. Just a thought 😊 On Thu, 5 Sept 2024, 20:54 Benoît Minisini, < benoit.minisini@xxxxxxxxxxxxxxxx> wrote: > Le 05/09/2024 à 20:56, Linus a écrit : > > Hello, > > > > It seems that the ‘.copy()’ function available for an Array of Classes > does not create a copy in a way the new copy has different pointers as > reference but the same as the original Array. > > > > So I guess use ‘.copy()’ for base type of array of objects/variables > like String[], Integer[], etc, works as expected, but for an Array of > Custom Classes not. > > > > Example: > > > > Class CVarExpect > > > > ‘ Gambas class file > > > > Public Subject As String > > Public Expect As String > > Public ResponsesData as String > > Public Responses As String[] > > > > Public Sub _new() > > > > Responses = New String[] > > > > End > > > > > > ‘ ——————————————————— > > > > Dim CVarExpertArray = New CVarExpect[] > > Dim NewCVarExpectArray = New CVarExpect[] > > > > NewCVarExpectArray = CVarExpertArray.Copy() > > > > > > Can someone confirm that COPYING a custom Array of Classes doe not > create a complete new Object but just create a new object that refer to the > existing one ? > > > > Thank you > > > > > > Olivier Cruilles > > > > > > Array.Copy() copies the contents of the array. If the array contents are > objects references, the references are copied, not the objects > themselves of course. > > Regards, > > -- > Benoît Minisini. > > >
Re: Object copy function question | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |
Object copy function question | Linus <olivier.cruilles@xxxxxxxx> |
Re: Object copy function question | Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx> |