[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Object copy function question


...it doesn't look that way to me.


(Having obviously created the Class "CVarExpect")

Public Sub Form_Open()

  Dim CVarExpertArray, NewCVarExpectArray As CVarExpect[]

  CVarExpertArray = New CVarExpect[]
  
  Print CVarExpertArray

  NewCVarExpectArray = CVarExpertArray.Copy()
   
  Print NewCVarExpectArray

End





5 set 2024, 20:57 da olivier.cruilles@xxxxxxxx:

> 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
>
>


References:
Object copy function questionLinus <olivier.cruilles@xxxxxxxx>