Página 1 de 1

AAdd - Strange behavior

Publicado: Mié Jun 29, 2016 9:27 pm
por emeasoft
Good Afternoon,

We would like to know if this behavior from AAdd is correct or a bug.

Consider the code:

Código: Seleccionar todo

METHOD Button1Click( oSender ) CLASS TForm1

  LOCAL a02 := {1}
  
  F001(a02) //NOT PASSED BY REFERENCE
  
  LogDebug(a02) //LOCAL VARIABLE SHOULD NOT BE CHANGED IN FUNCTION F001
  
  MsgInfo("OK")

RETURN Nil
//------------------------------------------------------------------------------
FUNCTION F001(f1)
  
  LOCAL a01 := {}
  
  a01 := f1
  
  AAdd(a01, 2)  //SHOULD CHANGE ONLY LOCAL FUNCTION F001 VARIABLE a01,
                //BUT CHANGES f1(Button1Click a02)
RETURN NIL
//------------------------------------------------------------------------------
The AAdd function changes the LOCAL variable from Button1Click method, even if it's not passed by reference.
Changing AADD(a01, 2) for a01 := {1, 2} solves the problem.

P.S: There is a simple test project with the code above attached.

- André Corrêa

Re: AAdd - Strange behavior

Publicado: Jue Jun 30, 2016 2:56 pm
por Claudio C
The arrays are always passed by reference (though not place @ the pass as a parameter)
If you need to pass the "value" but not "reference" use aclone() function that generates a copy of the array
regards