Directives
LOCAL Designation of Local Data
   
Format 1. Assign Local Variables: LOCAL varlist
2. Define Local Properties (OOP): LOCAL prop1[OBJECT], prop2 [OBJECT]....
3. Define Local variables in Functions: DEF FNxxxxx ( LOCAL var [ , LOCAL var ...] )

Where:

OBJECT Optional keyword identifies that the property contains an object identifier to another object.
prop1, Property names –treated like any other variable in the system. (In
prop2 ... Object Oriented Programming, data is referred to as properties.)
varlist Variables to be used temporarily in the execution of a subroutine, subprogram, FOR/NEXT, SWITCH/END SWITCH, WHILE/WEND, REPEAT/UNTIL or user-defined function.
   
Description The LOCAL directive is used to reassign variable names temporarily, without affecting the original contents. In Object Oriented Programming (OOP), the LOCAL directive is similar to the PROPERTY directive, but is used to declare data that is only visible to processing logic.
   
Format 1 Assign Local Variables

LOCAL varlist

Use this format to reassign variable names temporarily, without affecting the original contents. If the variable name supplied in the LOCAL directive is in current use, ProvideX will preserve its value/contents. Once the current FOR/GOSUB stack has been cleared or the program is exited, ProvideX restores variables that were designated local to their original values. (Local variables are only active until the current stack is cleared.)

The LOCAL directive can take an assignment during declaration; however, direct assignment does not work for arrays that are declared as local.

Example:

In the example below, X is designated as local for both subroutines (CHK_IT and LOOP), so the value of X is restored to its original value "1234" after the GOSUB stack is cleared for each subroutine. Since X$ was not designated as LOCAL in the LOOP subroutine, its value has changed from "START TEST, X=" to "LOOP" after the GOSUB stack for the LOOP has been cleared.

1030 LET X=1234,X$="START TEST, X="; PRINT X$,X
1040 GOSUB CHK_IT
1050 PRINT "TEST DONE"
1060 GOSUB LOOP
1070 PRINT X$,X," DONE"; STOP
 
6000 CHK_IT:
6010 LOCAL X$,X; LET X$="CHECK X:"; PRINT X$,X
6020 LET X=X+10
6030 PRINT X$,X
6040 RETURN
 
7000 LOOP:
7010 PRINT "START LOOP, X=",X
7020 LET X$="LOOP" ! Not designated as LOCAL
7030 FOR LOCAL X=1 TO 4
7040 PRINT X$,X
7050 NEXT X
7060 RETURN
 
-:run
START TEST, X= 1234
CHECK X: 0
CHECK X: 10
TEST DONE
START LOOP, X= 1234
LOOP 1
LOOP 2
LOOP 3
LOOP 4
LOOP 1234 DONE

Variables in function definitions can be designated as local to prevent changes in program variables:

0010 DEF FNXY(LOCAL X,LOCAL Y,LOCAL Z)=X+Y+Z

   
Format 2 Define Local Properties in Object Oriented Programming

LOCAL prop1[OBJECT], prop2 [OBJECT]....

In Object Oriented Programming, the LOCAL directive can be used to define the properties for an object class that are not exposed to external applications. They can be accessed during the execution of program logic within the object class itself.

This format of the LOCAL directive is similar to the PROPERTY directive: variable declarations may include dimensioned arrays and object references. LOCAL properties are typically used for:

  • File handles (if the object is maintained on a file).
  • Security information.
  • Flags and status information used by the programming logic.

If the local variable contains an object identifier to another object, specify the keyword OBJECT after the variable name. When the object is deleted, ProvideX will use the REF( ) function against the object identifier to remove it (as long as it has no other references); e.g.,

DEF CLASS "Customer" LOCAL File OBJECT

When you delete an object whose class is Customer, then the system reduces the reference count of the object whose identifier is in File and, if it is no longer being referenced, deletes it as well.

Refer to the following functions and directives for related information on Object Oriented Programming:

DEF CLASS Define Object Class
DROP CLASS Delete Class Definition
DROP OBJECT Delete Object
FUNCTION Declare Object Method
LIKE Inherit Properties
LOAD CLASS Pre-Load Class Definition
PROGRAM Create/Assign Program File
PROPERTY Declare Object Properties
RENAME CLASS Change Name of Class
STATIC Add Local Properties at Runtime
NEW( ) Function
REF( ) Function

   
Format 3 Define Local variables for user defined functions

DEF FNxxxxx ( LOCAL var [ , LOCAL var ...] )

When defining a user function, the LOCAL keyword can be used to specify that the variables declared in the paramerer list are local to the function. That is the assignment of values from the function invocation parameter list will only effect the variables while within the function.