Alaska Software Inc. - Array by reference
Username: Password:
AuthorTopic: Array by reference
Claudio Driussi Array by reference
on Wed, 31 Jan 2018 18:23:50 +0100
Hi everybody,

I have a question about arrays, hope I can explain my though

a sample:
--------------------------------------
function test_arrayfilter
   local a1 := {}
   local a2 := {}
   local i

   for i := 1 to 10
     aadd(a1, {i, "row "+str(i)})
     next i

   aadd(a2, a1[3])
   aadd(a2, a1[4])
   aadd(a2, a1[5])

   a2[1,2] := "modified"  point 1

   tt( @a2[2] )  point 2

return nil
static function tt(a)
   a := nil
return nil
--------------------------------------

At point 1 as expected I modify both element 2 of a2 array
and element 4 of a1 array. I use this very often

But at point 2 I have no solution to put to nil both a2[2] and a1[4].
I would like to find some way to catch the index of element a1[4]
starting from a2[2].

If they share the same address, if I can get the address of a2[2],
I can scan a1 until I find a1[4]

P.S. Found 

In the meanwhile i wrote this post I found the solution, so I
still post it hoping it helps someone.

version 2
--------------------------------------
function test_arrayfilter
   local a1 := {}
   local a2 := {}
   local i

   for i := 1 to 10
     aadd(a1, {i, "row "+str(i)})
     next i

   aadd(a2, a1[3])
   aadd(a2, a1[4])
   aadd(a2, a1[5])

   a2[1,2] := "modified"

   i := a2[2] == a1[3]  .f.
   i := a2[2] == a1[4]  .t.

return nil
--------------------------------------

I can check identity with

a2[2] == a1[4]

Best regards
Claudio Driussi