Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The m. variable thing
Message
De
22/11/2004 13:09:51
 
 
À
22/11/2004 12:57:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00962544
Message ID:
00963564
Vues:
7
>>Thanks, Elmer. Like you said, as you're sure I know... As had been said, in this thread, the use of variable naming conventions ( e.g. lcCustName for CUSTOMER.CUSTNAME, lnUserID for USER.USERID, etc), which I strictly adhere to (except for using good-ole "I" for loops) would seem to obviate the need for such differentiation. Whatever, I've never (knowingly!!!!) been bitten. As someone else has said, always using the alias when referring to fields doesn't hurt, and further clarifies the situation. Some other languages you have to do this anyway.
>
>Terry,
>
>Yes, using alias.fieldname for fields does help make code more readable and other languages may require that, but it really does nothing to eliminate the possibility of ambiguous references to variables. Because of fields taking precedence over memvars, when you have a field in the current alias and a variable of the same name, when referencing the variable without the m., VFP WILL read the field instead of the variable. This is the "by design" behaviour even if every other place in code you reference the field as Alias.fieldname. This is a rule in VFP that you cannot change. You indicate that your naming convention prevents that possibility, but really there is nothing to prevent the off chance that somone using your code may have a table open in the current workarea that may have a field named lnUserID or any other memvar name thay you may have used.
>
>I have been bitten by this several times when using code from others, so I tend to practice defensive programming and use m.variablename to reference variables and alias.fieldname for fields. If you have never been bitten, that is great, but for anyone lurking here, it might be a good thing to be aware of this fact and know that intermittent logic errors can occur caused by this behaviour. Errors like this can be very difficult to track down.

Ah, Gotcha

Although you may use the alias all the time, that one occasion that you ref. a same-named var, the compiler thinks it's a field ref WITHOUT the alias. Noted and digested

Cheers Elmer

terry
- Whoever said that women are the weaker sex never tried to wrest the bedclothes off one in the middle of the night
- Worry is the interest you pay, in advance, for a loan that you may never need to take out.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform