Variables exist only while an application is running or during the Visual FoxPro session in which they are created. To specify the scope of a variable, use the LOCAL, PRIVATE, and PUBLIC keywords.
-
LOCAL creates variables or arrays that can be used and modified only in the program they are created, and cannot be accessed by higher or lower level programs. Local variables and arrays are released once the program containing them stops running.
-
PRIVATE hides variables or arrays that were defined in a calling program from the current program. You can then reuse those variable names in the current program without affecting the original variables. Once the program containing PRIVATE has stopped running, all variables and arrays that were declared privately are again available.
-
PUBLIC defines global variables or arrays. Global variables and arrays can be used and modified from any program you run during the current Visual FoxPro session. Any variable or array you create in the Command window is automatically public.
Accessing Variables
If a variable has the same name as a field, Visual FoxPro always gives precedence to the field name. You can reference the variable using m.
or m->
plus the variable name, as in the following examples.
В | Copy Code |
---|---|
? m.cFname ? m->cFname && print value in cFname ? cFname && prints contents of field cFname |
For more information about these commands, see the appropriate topics in Help.
Note: |
---|
In object-oriented programming you can create properties of objects to hold values instead of using variables. For more information, see Object-Oriented Programming. |