Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recursive Remove Directory
Message
From
13/12/1999 02:13:33
 
 
To
12/12/1999 21:06:28
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00302015
Message ID:
00302596
Views:
38
>>>>Oh. Since they're not local, are they public?
>>>
>>>No, they are not public. They are a weird kind of animal! They behave as private /public variables for all called func/proc/methods. But they are released as soon as the func where they ar declared is finished.
>>>
>
>>How is this different from the behaviour of PRIVATE variables?
>
>Did you try the short code sample from my previous message? It clearly shows the difference.
>
>So, PRIVATE only hides a variable that already exists at a higher level. Here's what happens whenever you use a variable without any declaration:
>- The variable name is looked up at any higher level
>- If found, the same variable is used. If not found, a new variable is created.
>- If a new variable was created, then it released at the end of the proc.
>
>Here's what happens when you use a PRIVATE variable:
>- The variable is created and used.
>- The same variable is released at the end of the proc.
>
>This means that any used-but-not-declared variable may modify some variable with the same name from a higher level. This may be desired some times, but it's dnagerous and I advise against such use.
>
>Vlad

If a variable at "any higher level" has been declared LOCAL, it will not be used in your first case. The only way it can be used is if it was:
- explicity declared PUBLIC or PRIVATE
- simply used without any declaration

Using without declaration in the higher level routine is equivalent to explicitly declaring it PRIVATE.

I think the point is that a variable CREATED by using it without declaration, has exactly the same scope as a PRIVATE. As you point out, it must be understood that an undeclared variable within the scope of a higher-level PUBLIC, PRIVATE or undeclared variable of the same name will simply reference that variable.

I think everyone here understands the scope of the variables discussed. I agree totally that the use of undeclared variables is almost always undesirable; I feel the same way about PRIVATEs as well.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform