I received a question:

 

As you know most of variables in methods and procedures are local, not private. Its very tedious to declare them as local every time. Why don't you do something like

SET PRIVATE OFF in VFP? When it is on(by default) -all variables are private by default. otherwise they are local. Regards.

 

 

When the user creates a variable without declaring it:

 

MyVariable="New variable value"

 

VFP will create the variable as PRIVATE for historical and compatibility reasons. This means the variable is visible in lower level procedures. For example, run the code below, with and without the LOCAL line.

 

A subsequent release of Foxpro (Probably FoxBase? Does anybody recall which version?) introduced the concept of LOCAL variables, which are not visible to lower level procedures. If the version of Fox had changed the behavior to make all variables LOCAL instead of PRIVATE, then existing applications would break.

 

If we added some global command like “SET PRIVATE OFF”, then many existing applications could break. A lower level procedure would not see a variable any more and would cause an error to occur.  You say: “So what? I’m writing a new application and I don’t care about older applications”.

 

There are many places in Fox that there are “older applications” that you might use. Intellisense, Wizards, Builders, Class Browser, Object Browser, Component Gallery, and other Productivity Tools will be affected by such a change. These tools were written by many authors over the years, with many different coding styles.

 

To help developers determine which variables were not declared, the LanguageOptions Property of _VFP was introduced in VFP7. When you run VFP code with this option set to 1, Debug Output window shows variable creations that were not previously declared.

 

Try running the Class Browser with _VFP.LanguageOptions=1 and the Debug Output window open

 

 

 

CLEAR

ACTIVATE WINDOW "Debug Output"

_vfp.LanguageOptions=1

*LOCAL MyVariable

MyVariable="New variable value"

foobar()

PROCEDURE Foobar

      ?MyVariable

RETURN

 

LangOptionsErr,10/28/05 10:44:03 AM,4,TT1,D:\FOX90\TEST\TT1.FXP,MYVARIABLE