Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Initializing Variable
Message
De
29/07/1998 21:18:23
 
 
À
29/07/1998 10:00:25
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00122209
Message ID:
00122561
Vues:
13
>In the VFP documentation, PRIVATE pcVariable does not initialize pcVariable.

Right.

>It just makes pcVariable private to that method or procedure. I didn't realize that pcVariable=whatever automatically made pcVariable private.

It makes it private only if the variable doesn't exist at a higher level. In fact, it doesn't make it private in any case, but pcVar = whatever creates pcVar if it doesn't exist already and pcVar behaves after that (again, if it didn't exist already) like a variable declared private (ie it will be seen at any lower level at it will not be seen at a higher level).

The PRIVATE keyword only hides any variable with the same name from a higher level.

>Where would you use a PRIVATE variable?

Where ever you need a variable that is not from a higher level and that must be seen somwhere at a lower level.

As I already said, try to use LOCAL instead of PRIVATE. It leads to better encapsulation (so, better and clearer code) and avoids a lot of bugs. Also, try to declare (PRIVATE, LOCAL, PUBLIC depending on what you need) all your variables. This also leads to better code, less bugs and provides a place where you can look if a variable is used in a certain piece of code.

Vlad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform