Click or drag to resize

Functions.MemVarBlockSym Method

Return a set-get code block for a given memory variable.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.18
 FUNCTION MemVarBlockSym(
	symMemvarName AS SYMBOL
) AS Object
Request Example View Source


Type: Symbol

Return Value

Type: Object
A runtime code block (implemented as an object) that, when evaluated, sets (assigns) or gets (retrieves) the value of cMemvarName.
If cMemvarName does not exist, MemVarBlock() returns a NULL_OBJECT.
The code block created by MemVarBlock() has two operations, depending on whether an argument is passed to the code block when it is evaluated: If the code block is evaluated with an argument, it assigns the value of the argument to cMemvarName. If the code block is evaluated without an argument, it retrieves the value of cMemvarName.
Tip Tip
MemVarBlock() creates set-get blocks only for variables whose names are known at runtime. MemVarBlock(), therefore, cannot be used to create set-get blocks for local or static variables.
The same restriction applies to creating blocks using the macro operator (&).
This example compares MemVarBlock() to a code block created using the macro operator (&). Note that using MemVarBlock() allows you to avoid the speed and size overhead of the macro operator:
1PRIVATE var := "This is a string"
2// Set-Get block defined using macro operator
3cbSetGet := &("{|setVal|;
4        If(setVal = NIL, var, var := setVal)}")
5// Set-Get block defined using MemVarBlock().
6// It is the functional equivalent of cbSetGet above
7cbSetGet := MemVarBlock("var")
See Also