Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Variable scope
Message
From
17/08/1999 15:42:48
 
 
To
17/08/1999 15:32:31
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00254565
Message ID:
00254675
Views:
24
>Ed,
>
>You said making public variables can have all kinds of side effects. What side effects are there?

The obvious ones - since you don't hgave to declare a variable in VFP before using it, you can stomp on an existing global accidentally with no warning. There are some problems with pass by reference when you pass a PUBLIC or PRIVATE varialbe by reference, and then try to use it by its original name in a function or procedure that receives the variable by reference (it hides the PUBLIC/PRIVATE name, since VFP would get extremely confused if two name entries in the active Name table point to the same Value structure.) PUIBLIC variables persist until you explcitly release them, so they can end up being accidentally initialized. In general, except in very rare situations, there's no need for PUBLIC variables if you design your application properly.

In this case, since you need to have the variables visible to methods in a form, the proper scope of the variable is the life of the form object; you can get that easily with properties of a Form. You can further restrict the visibility of form properties to just inside the form instance if you like. Encapsulation avoids most of the accidents that occur because of accidental, unplanned side-effects.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform