Information générale
Catégorie:
Codage, syntaxe et commandes
>*pay attention to the macro syntax
>FOR i = 1 TO ALEN(loObject.&lcArrayName,1)
> lcMess=lcMess+' '+loObject.&lcArrayName.[i]
>ENDFOR
That's clever. In fact, if you have a character string that serves to resolve the object reference to the array, then you can play several variations on the same theme.
Lets assume that you have a property array called oMyObject.aMyArray[10]. Put a character string that references the array into a memory variable: cMyArrayRef= "oMyObject.aMyArray"
Now you can pass cMyArrayRef to a function and have the function do either of the following:
1. Extract the entire contents of the array into an internal, temporary array by saying:
ACOPY(&cMyArrayRef, aSomeNewArray) -- this will work fast because the macro only needs be evaluated once
2. Use the EVAL() function to access the Nth element of oMyObject.aMyArray by saying:
cThisElement=cMyArrayRef + "(N)"
Now you can change the value of N as often as you like and resolve the value of the Nth element by simply asking for Eval(cThisElement)
You might think that you can use the Eval function to create an object reference explicitly for the array:
oMyArrayRef=Eval(cMyArrayRef), and proceed by enumerating oMyArrayRef(1), oMyArrayRef(2), etc.
...but this won't work. Instead, Eval(cMyArrayRef) returns the value of the first element in the array.
The big suck is that VFP won't let you simply pass the property array by reference.
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement