The usecallerslocalvariables statement temporarily swaps out a subroutine’s current local variables with the local variables of the procedure that called this subroutine. The statement can be used only in a subroutine, not in a calling procedure.
Any local variables created in a procedure can normally only be accessed in that procedure and not any other. In some special cases, however, it can be useful for a procedure to access the local variables of a subroutine that it has called. This is especially true when you are creating procedures for use as custom statements, and when using the execute statement.
Panorama has two statements that allow a procedure to access the local variables of the procedure that called the current procedure: UseCallersLocalVariables and UseMyLocalVariables. These statements are normally used as a pair. The UseCallersLocalVariables statement temporarily swaps out a subroutine’s current local variables with the local variables of the procedure that called the subroutine. The UseMyLocalVariables statement swaps the variables back again. While the variables are swapped the calling procedure has full access to the local variables of the subroutine. You can even create new local variables, which become local variables belonging to the calling procedure. Here is an example of a subroutine called * MakeAlphabet* that creates a local variable named alphabet and initializes it with 26 letters.
usecallerslocalvariables local alphabet alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ" usemylocalvariables
A procedure could call this subroutine as shown below.
call MakeAlphabet message alphabet
The message statement will display ABCDEFGHIJKLMNOPQRSTUVWXYZ even though this local variable wasn’t created in the calling procedure.
Note: In this example we could have left off the final UseMyLocalVariables statement. Panorama will automatically switch the variables back when the end of the procedure is encountered, or when a return statement is executed.
UseCallersLocalVariables can only be called from inside a subroutine. – If the current procedure was not called as a subroutine, there are no “callers” variables, so an error occurs.
|10.0||Updated||Carried over from Panorama 6.0, but with improved handling. In previous versions of Panorama the UseCallersLocalVariables and UseMyLocalVariables statements did the same thing -- swap local variables with the calling procedure. Now Panorama actually keeps track of which set of local variables are in use, instead of just swapping. So if you use this statement twice in a row, you'll still be using the caller's local variables (in previous versions this would have switched you back to the current procedure's normal local variables). Also, Panorama now allows you to omit the closing UseMyLocalVariables. You can simply return from the procedure at any time and Panorama will take care of fixing up local variable usage.|