Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
EVALUATE and macro substitution alternatives
Message
De
28/06/2000 14:13:36
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00385373
Message ID:
00385954
Vues:
13
>
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
Fil
Voir

Click here to load this message in the networking platform