[Gambas-user] String array empty after SUB (Gambas 2)

Bruce Bruen bbruen at ...2308...
Thu Feb 23 09:48:10 CET 2012


On Thu, 2012-02-23 at 09:09 +0100, Rolf-Werner Eilert wrote:
> That was it, Jussi, thanks a lot!
> 
> Here we can see what it is good for to know about OOP :-)
> 
> Regards
> 
> Rolf
> 
> Am 22.02.2012 18:49, schrieb Jussi Lahtinen:
> > Just quick thought... maybe this "felder = feld.Copy()" gives new object
> > reference feld to felder.
> > And because feld is declared locally, the it is null after the sub and so
> > is also felder.
> >
> > Perhaps you need to do "felder = feld.Copy()" manually with for each...
> >
> > Jussi
> >
> >
Interesting! I must admit that I have never used String[].Copy but I
would have expected that a "deep" copy meant that every string in the
array was copied to the target array, not just that a reference was
created.

So what is the difference between 
	felder=feld
and
	felder=feld.Copy
?

In the former case I would expect a reference but in the latter I would
have assumed a full transfer of the whole array replacing whatever was
in felder.

Further, within the example quoted by Rolf, if I explicitly copy every
string in feld to felder, viz
	Dim wkStr as String
	felder.Clear (or felder = New String[] **)
	for each wkstr in feld
		felder.Add(wkstr)
	next
will it work?

** the latter would be interesting, re-initialising a String[] array in
a called routine???

Bruce







More information about the User mailing list