Information générale
Catégorie:
Codage, syntaxe et commandes
>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
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