[Gambas-user] Array question
ron
ronstk at ...239...
Tue Oct 12 14:07:13 CEST 2004
On Tuesday 12 October 2004 13:41, Benoit Minisini wrote:
> On Monday 11 October 2004 14:15, Paolo Saudin wrote:
> > ron wrote:
> > >On Saturday 09 October 2004 11:11, Paolo Saudin wrote:
> > >>Hi all,
> > >>I need to use a multidimensional array ( x1[0][0] , x1[0][1] , x1[1][0]
> > >>, x1[1][1] ... ) and at a certain time,
> > >>I want to copy it in a bakup array in order to work with the new one
> > >>without loose the original data.
> > >>Here's my problem : when I copy ( x2=x1.copy() ) a single dimension
> > >>array all it works as expected,
> > >>but as soon as I use a multidimensional one, the original is treated as
> > >>a "referenced" copy and get modified as well.
> > >>Attached there is an example to demonstrate it clearer :-). Is there
> > >>another way to deep copy two arrays?
> > >>
> > >>Many thanks,
> > >>Paolo
> > >
> > >the array.copy is not an new array with a copy of the content.
> > >It is the same but with a different name.
> > >
> > >arrB = arrA.copy()
> > >arrB is the same as aarA only the name differs.
> > >
> > >The exact name should be .Clone() I think.
> > >or arrB.Alias( arrA ) or arrB.Link(arrA)
> > >
> > >A copy is an new instance of it with the content of the source.
> >
> > I tried but the only methods available for a Variant[] are _Add Clear
> > Copy Insert Pop Push Remove Resize Reverse Sort
> > _and so I couldn't manage to really get a copy of the array. In the
> > Gambas-wiki, the copy() function is said to return a true copy of it,
> > if I understand it correctly ?. FUNCTION Copy ( ) AS Variant[] Returns a
> > deep copy of the array.
> > Paolo
> >
>
> You are right and Ron is wrong. Copy() returns a deep copy of the array.
> But be careful: if there is an object reference in the array, then only the
> reference is copied. The object is not cloned (there is no clone support in
> Gambas object model).
>
> Regards,
>
Sorry if I'm wrong but look to this mesage.
Re: [Gambas-user] Methods Copy.
From: Benoit Minisini <gambas at ...1...>
To: gambas-user at lists.sourceforge.net
Date: 2004-07-22 23:52
On Thursday 22 July 2004 23:07, Leo Barnhoorn wrote:
> Hello Benoit,
>
> Can you tell me how the methode copy works of the Byte[] array.
>
> Thanks.
>
> Regards,
> Leo.
>
DIM hOld AS Byte[]
DIM hNew AS Byte[]
hOld[0] = 1
hNew = hOld.Copy()
hNew[0] = 2
PRINT hOld[0]
This returns 2. If you don't make a copy, this will return 1.
Regards,
--
Benoit Minisini
mailto:gambas at ...1...
here is in hNew [0] set to 2
print is hOld [0] and returns 2
in this way hOld is changed by changing hNew
So the cant be different.
More information about the User
mailing list