In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

AAdd - Strange behavior

Xailer professional forum in English
Responder
Avatar de Usuario
emeasoft
Mensajes: 1088
Registrado: Mié Abr 01, 2009 4:12 pm
Ubicación: emeasoft
Contactar:

AAdd - Strange behavior

Mensaje 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
Adjuntos
AADDTeste.zip
(43.17 KiB) Descargado 180 veces
Claudio C
Mensajes: 60
Registrado: Dom Sep 20, 2015 8:13 pm
Ubicación: Buenos Aires

Re: AAdd - Strange behavior

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