Information générale
Catégorie:
Codage, syntaxe et commandes
>
What's the difference between:
fldname='MyTable1.field1'
replfldname='MyTable2.field2'
replace (fldname) with evaluate(replfldname)
versa
replace &fldname. with &replfldname.
What would be more efficient?
<
Macro substitution allows any single VFP statement to be put into a string and interpreted at runtime. EVALUATE() functions only on expressesions which return a value -- a subset of what macro substitution can do. Name expansion is also a subset, but not overlapping with EVALUATE(), which allows a "name" (of a table, field, etc.) to be couched as a string variable rather than as a literal.
The less work required in parsing the string, the faster the operation will execute. EVALUATE() and name expansion have much less overhead -- because they have more limited capabilities -- and thus execute faster.
The one tricky case occurs in statements where macro substitution is performed once, but EVALUATE() is performed for each of a set of items. In this case, macro substitution will probably give better performance in specific situations and in general is the better choice.
An example of the tricky case:
lcSearchString = "ATable.cDesiredInfo = 'This one'"
SCAN FOR &lcSearchString && macro substitution performed once for the SCAN
ENDSCAN
SCAN FOR EVALUATE (lcSearchString) && EVALUATE() performed for each record of table
ENDSCAN
This is also something to keep in mind with SELECT statements where macro substitution occurs once for the entire statement.
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