Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Defining a global property for an application
Message
From
10/04/2000 21:53:49
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00357663
Message ID:
00357782
Views:
16
>>>>VFP 5.
>>>>
>>>>I have forgotten how to do the following.
>>>>1. Define a property that is accessible anywhere in the application.
>>>>2. Use it in forms or other programs.
>>>>
>>>>Any help appreciated.
>>>
>>>In your main prg declare a variable as PUBLIC
>>>
>>>It is always a good practice to track the PUBLIC variables very closely.
>>
>>Bret,
>>
>>There is no reason that a variable declared in the start up program of an application needs to be PUBLIC! A private variable is visible to everything in the application.
>
> Hi Jim,
>
> I made the same assumption, but it's not a truly right. I declare a private variable in a main program pcTable and assign pcTable='' (This is important to assign a value, before using a variable). Then I create a form and test, if this variable is still visible. I found, that if I issue Read Events after
>do form MyForm, this variable is still visible in all methods and events, otherwise this variable is visible only for Init and then it becomes out of scope. You can test it.

No, you don't understand scoping of PRIVATE variables. PRIVATE implies that the variable exists and is visible from the creating function or method downward - once the function or method terminates, the variable goes out of scope. A variable declared PRIVATE in the Init disappears once the INIT completes because it is no longer in scope - exiting the Init makes all PRIVATE and LOCAL scope things go away. This is a fundamental difference between a PRIVATE variable (scopes to the life of the function/method that creates it) and a member property of an object, whose existance is scoped to the life of the object that holds it.

Jim is 100% correct about the visibility and scope of a PRIVATE declared in the main .PRG of an app - if you are not creating a PRIVATE in the main line code which terminates the application then it is not equivalent to a PUBLIC variable. If you create a variable in a method, it goes away when the method call completes.

>
> Thanks.
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