Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A basic thought about LOCAL variables
Message
De
28/12/1999 19:27:41
 
 
À
28/12/1999 18:06:45
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00309158
Message ID:
00309611
Vues:
31
Since everyone on the UT is involved with this thread cept me, I guess now's as good a time as any for me to jump in.

PUBLIC vars - Once a var is declared Public, it can be seen by any piece of code in the application. Your Main.prg can look at the variable. Your Menu can look at it, anything.

PRIVATE vars - Can only be seen by lower programs in the calling chain.

Ex)
ProcedureA
Private lcMyName && or
lcMyName ="Perry" && Since without a declaration its Private
..
..
..
Do ProcedureB
Do ProcedureC
Do ProcedureD

Procedure B,C,D can all see lcMyName, and change it. To further explain Privates, if Procedure B,C, or D created a PRIVATE var, Procedure A could not see it, since the variable would be destroyed once that procedure ran.

Using PRIVATES is dangerous since they can be edited by all lower programs. But at a minimum they are self releasing, since as soon as the procedure that declared them is done, the var disappears.

You can also see the effect of Private vs. Public by creating a simple little program:

* Myprogram
Private lcvar1
Public lcvar2

Then run this program from the command window. after the program, lcvar2 will still exist.

>Sorry if I'm not getting it. The PUBLIC is seen by the calling procedure and the PRIVATE is not while APROC is still living (which can be tested using the locals window while stepping through the code I provided). Why is that not a different difference?

(On an infant's shirt): Already smarter than Bush
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform