usefunctioncallerslocalvariables
usefunctioncallerslocalvariables

The usefunctioncallerslocalvariables statement temporarily swaps out a procedures current local variables with the local variables of the procedure that called this the call(, callwithin( or execute( function.

Parameters

No parameters.

Description

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 function code to access the local variables of the code that invoked it. This is especially true when you are writing custom functions.

Panorama has two statements that allow a procedure to access the local variables of the procedure that called the current procedure: UseFunctionCallersLocalVariables and UseMyLocalVariables. These statements are normally used as a pair. The UseFunctionCallersLocalVariables statement temporarily swaps out a procedures current local variables with the local variables of the procedure that called this function. The UseMyLocalVariables statement swaps the variables back again. While the variables are swapped you have full access to the local variables of the caller. You can even create new local variables, which become local variables belonging to the calling procedure. Here is an example that creates a local variable named alphabet and initializes it with 26 letters.

    usefunctioncallerslocalvariables
    local alphabet
    alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    functionvalue alphabet
    usemylocalvariables

A procedure could call this function as shown below.

    message call(MakeAlphabet)
    message alphabet

This code will display ABCDEFGHIJKLMNOPQRSTUVWXYZ twice, even though this local variable wasn’t created in this 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 function is encountered, or when a return statement is executed.

Error Messages

UseFunctionCallersLocalVariables can only be called from Function code. – If the current procedure was not called as a function, there are no “callers” variables, so an error occurs.

See Also

- call( -- allows a procedure to be called as a subroutine within a formula and return a result.
- callwithin( -- allows a "mini-procedure" to be called as a subroutine within a formula and return a result.
- execute( -- allows a formula to execute a sequence of statements and return a result.
- usecallerslocalvariables -- 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.
- usemylocalvariables -- reverses the action of the UseCallersLocalVariables statement, switching back to the current procedure's normal local variables.

History

Version | Status | Notes
10.2 | New | New in this version.