Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
A basic thought about LOCAL variables
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00309158
Message ID:
00309699
Vues:
28
>>>I have to defend myself... :) Although I understand what you're saying (this message and others) and I also agree up to a certain point. :)
>>
>>*snip*
>>
>>FWIW, Paul, I agree with you. They ARE different! :)
>
>Fred,
>
>Ok, one of you tell me exactly how they are different. That is, how is a private variable created through assignment different from a private variable that was declared before it was created through assignment. The variables are NOT any different, the behavior of the program may be different but the variables are PRIVATE. In VFP the default scoping for a variable is PRIVATE.
>
>Please explain to me the different behavior, scoping, visibility or anything else between the two. There is no difference. If a private variable exists and lower level routine refers to that variable then that variable is affected. That is what PRIVATE is. If a routine asssigns a value to a name that does not exist as a variable, then the variable created is PRIVATE.

Jim,

I agree with Ed's definition. It's not so much the behavior, but the scoping that is different. Well, to me it is somewhat the behavior, too. If you have the code:

*MAIN.PRG
PRIVATE xyz
xyz = 123
DO test1
DO test2
DO test3
*EOP

*TEST1.PRG
PRIVATE xyz
xyz = 456
*EOP

*TEST2.PRG
xyz = 789
*EOP

*TEST3.PRG
PRIVATE xyz
*EOP


In MAIN.PRG before you execute any of the test procedures, xyz has the value of 123.

At the end of TEST1.PRG, there are now two variables xyz, one belonging to MAIN.PRG with the value 123, and one belonging to TEST1.PRG with the value of 456. Only the 456 value can be seen. This second variable will be destroyed at the completion of this code. The MAIN.PRG xyz variable would still contain 123. If TEST1.PRG was the main program, it would create a private variable xyz, assign it a value of 456, and it would be destroyed at the end of the code. No difference.

At the end of TEST2.PRG, there is only one variable xyz in scope, and it now has the value of 789. The variable will not be destroyed at the completion of this code. If TEST2.PRG was the main program, it would be different. There would be a private variable xyz created, assigned a value of 789, and it would be destroyed at completion of the code. This is the difference.

At the end of TEST3.PRG, there is still only one variable xyz with a value of 789. However, it's value cannot be seen from within TEST3.PRG. The existing xyz variable will not be destroyed at the end of the code.

My contention is that the way xyz operates is different when you declare it private (and assign it a value) vs. not declaring it (and assigning it a value). See TEST1.PRG & TEST2.PRG.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform