setlocalsfromdictionary
VALUES

The setlocalsfromdictionary statement converts a dictionary into a collection of local variables. The names and values of the local variables will be derived from the dictionary contents.


Parameters

This statement has one parameter:

values – dictionary containing values to be converted into local variables.


Description

This statement converts a dictionary into a collection of local variables. The names and values of the local variables will be derived from the dictionary contents. This example sets up four local variables, x, n, z and color.

setlocalsfromdictionary initializedictionary(
    "x","y",
    "n",42,
    "z","zoz",
    "color","blue"
    )

The example above is identical to this code:

let x = "y"
let n = 42
let z = "zoz"
let color = "blue"

So why not just use let statements? If the variable names are fixed in advance, you should. The advantage of the setlocalsfromdictionary statement is that both the variable names and values can be changed on-the-fly as the code runs. You can use all of Panorama’s options for setting up and modifying dictionaries, then convert the dictionary into variables.

One very useful application of this statement is to transfer local variables from one procedure to another. Normally a procedure cannot access another procedures local variables. You can pass them one at a time, but with setlocalsfromdictionary and the dictionaryfromvariables function you can transfer a batch of local variables at once. Here is an example that passes all the local variables in the current procedure as a single dictionary value to a subroutine it is calling.

call mySubroutine,dictionaryfromvariables(info("localvariables"))

The first line of the mySubroutine procedure can use the setlocalsfromdictionary statement to turn the values back into variables.

setlocalsfromdictionary parameter(1)
// mySubroutine now has all the same variables that the calling procedure had

Important Note: Keep in mind that the mySubroutine procedure now has a copy of the variables in the oalling procedure, not the original variables. If you have programmed using other languages, these variables have been passed by value, not by reference. So if you modify any of these variables, the modified value will not be passed back to the original procedure when the subroutine is finished. The original procedure will still have it’s original, unmodified variables. Of course you could pass the new values back the same way.


See Also


History

VersionStatusNotes
10.2NewNew in this version.