Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Local vs private
Message
From
10/08/2005 11:21:52
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01039725
Message ID:
01039876
Views:
21
Thanks Tom -
I only use public variables in 2 instances. The first is when I want a value to be seen by the entire application such as a security value that is referenced by all the controls on all the forms. The second is when I want to pass a value to a report, such as a variable report title, since I haven't found another way to do that. Any thoughts?
- Don

>Don;
>
>The concept of a Public variable is to allow an entire application to use the contents of the variable. Using VFP I do not use PUBLIC as it is not very object oriented. It is better to use Local variables and Private if necessary. When I was learning OOP the instructor insisted, “Create objects and send messages to those objects. Never use Public variables”!
>
>Public variables can be a problem as I have experienced. Eleven years ago we wrote a FoxPro 2.6 application, and Public variables were in use. All was well upon the applications release into production – until… At the end of the month a report was run and crashed the system. Someone had used the same Public variable with a different data type!
>
>Tom
>
>
>>Thanks Sergy, that explains a 3 hour puzzle I worked on this AM. But if the PRIVATE variables can be seen by the chain of functions and procedures that follow and initial routine, how does that differ from PUBLIC? Is it that the PUBLIC variable can be seen even if it wasn't identified in the calling program?
>>
>>
>>>The private variables/parameters are visible in the called programs. The LOCAL variables/parameters are only visible in the program where they have been declared.
PRIVATE pcVar1
>>>LOCAL lcVvar2
>>>
>>>pcVar1 = "PRIVATE"
>>>lcVvar2 = "LOCAL"
>>>? pcVar1
>>>? lcVvar2
>>>
>>>DO myprg
>>>
>>>PROCEDURE myprg
>>>? pcVar1
>>>? lcVvar2    && Error
>>>RETURN
>>>
Also, as you correctly noted, LOCAL defines variable. The PRIVATE only hides variable if it existed before or does nothing if variable didn't exist. Any variable that get value assigned w/o declaration became PRIVATE in scope.
>>>
>>>
>>>>Can someone give me a simple but clear understanding of the difference between LOCAL and PRIVATE? I've read the docs but they leave me unsatisfied. I understand that LOCAL actually creates a variable whereas PRIVATE does not. So is PRIVATE just a means to convert a public variable into a local one?
>>>>
>>>>Also LPARAMETERS vs PARAMETERS? One is LOCAL and the other is PRIVATE? I don't see the difference. Also, aren't variables created as LOCAL or PRIVATE by default without specifying? If so, what's the point?
>>>>
>>>>Thanks for any insights in this.
>>>>
>>>>- Don
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform