Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why cannot use & with Thisform.SomeProperty
Message
From
05/05/2009 18:39:13
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
05/05/2009 10:57:55
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01397844
Message ID:
01398040
Views:
109
>>replace (lcFiledName) with lcValue in (lcAlias) && this is much better and safer syntax
>
>Why is it safer -- seems to be only a matter in choice of syntax? Both accomplish the same task exactly every time, nothing more nothing less...

Not necessarily so. They are actually different beasts. Macro substitution can contain any part of a command, which will be substituted, the command will then be compiled and executed. A macro can contain expressions, clauses, whatever you want - as long as the final expanded command is syntactically valid. You can cut a random string out of any valid command, stuff it into a variable, replace the string with a macro containing that variable, and it will work:
select field1, field2, field3 from mytable into cursor crs1
lcCut="d1, field2, fiel"
select fiel&lcCut.d3 from mytable into cursor crs1
A name expression, OTOH, is used for names only. Names of files, variables, fields, windows, objects... With filenames, and generally with all the places where you'd expect the quotation marks to be mandatory but aren't. Example: in USE command, or a do form, report form - the names of the files are string literals, which don't require quotation marks (courtesy of authors of dBase) but are actually filenames. This is where the name expression does the job and a macro doesn't: imagine you have a table "number one.dbf".

You can put it as a literal, but now you discover that it actually needs quotes:
use number one
errors out, because it looks for number.dbf, doesn't find it (or does), but before that it analyzes the line and finds that "one" is not a valid clause, ergo syntax error. Let's call this syntax type A.
use "number one"
This syntax works (let's call it type B), because Fox now knows what to look for.

Now suppose you have put the name of the table in a variable:
lcDbf="number one"
* try macro, it will bang:
use &lcDbf
* try name expression:
use (lcDbf)
* try a combination of a literal and macro - it will work because you provided the quotes:
use "&lcDbf."
The first macro usage is equivalent to type A - it unpacks the variable, there are no quotation marks, boom. The second one doesn't require quotes, because it's a name expression, so VFP knows it's a variable containing a name, no need to parse a literal to get the name.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform