Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Private vars
Message
 
To
01/06/2001 11:10:53
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00513736
Message ID:
00513834
Views:
16
>>>>>reading a recent post, I read ( then proved ) that if you declear a private var in you main program it will have golbal scope.
>>>>>
>>>>>WHY!!!?!?!?!
>>>>>
>>>>>unless I'm mistaken, in most ( if not all ) other programming languages when you declair a private var it is scoped to that file, method, function, etc. I should be able to declair the Var isSomeThing as private anywhere in the program, and anywhere else ( other than that function, etc. ) isSomeThing should not exist, irregardless of how it came to that piece of code ( even if it is in the main.prg file ).
>>>>>
>>>>>I don't understand why the deviation on something so primitive.
>>>>>
>>>>>- jer
>>>>
>>>>Because the PRIVATE myVar1 will be visible for all the code called from the MAIN.PRG, so it is global for this application, but if you run another application from it's own MAIN prg, myVar1 will not be available for it. In case you declare PUBLIC myVar1, it will be accessible from both apps.
>>>>The PRIVATE variable is scoped for the current procedure/method and any others which may be called from it (excluding the case when the called procedure declares the same myVar1 variable name as PRIVATE, which "hides" this variable from the calling procedure variable)
>>>
>>>
>>>
>>>so what're saying is that if I declair a variable as public, an entirely different application written in fox can see ( and manipulate ) that variable?
>>
>>Kind of.
>>The variable declared PUBLIC exists until you explicitly RELEASE it or quit VFP. While developing, you may run different applications in your VFP session. If all of them will declare different PUBLIC variables and not explicitly release them they will hang around until you close VFP, possibly creating troubles for other applications. Depending on architecture the big application may consist of different APP or EXE modules called from the main menu. The same thing will happen. Or, you create an application, or module, or utility which possibly will be used later in another application. If you use PUBLIC variables in it, they might interfere with calling application which they know nothing about. Avoiding PUBLIC variables you eliminate the possibility of such errors.
>
>
>
>
>
>
>so...
>
>app1.exe:
> main.prg:
> public fSomething
> ! App2.exe
> . . .
>
>app2.exe:
> main.prg:
> This could use fSomething?
>
>- if so, what if "public fSomeThingElse" was is App2.exe? could that var be seen by app1? AFTER app2 closes?
>
>- I'm assuming that unrelated appications ( even if written in fox ) cannot see these var ( may sound like a rather obvious thought, but then this behaviour is not exactly standard either ). i.e. app1.exe and app2.exe are started by click-click on the icons or through run...
>
>- jer

If you start them separately in Windows they should not be visible to each other. However, (correct me if I am wrong) they will be using the just one instance of runtime library. IF I am not mistaken, I think I have seen something on UT long ago about possible conflicts between two apps even if they run this way. I was not able to find that message, but somebody might remember.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform