Click or drag to resize

Functions.MemVarBlock Method

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

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.16
 FUNCTION MemVarBlock(
	cMemvarName AS STRING
) AS Object
Request Example View Source


Type: String
The name of the variable referred to by the set-get block.

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 (&).
Tip Tip
Dynamic memory variables (PUBLIC, PRIVATE, PARAMETERS) are supported in the X# language and runtime for compatibility only.
In most cases the type can and should be replaced with lexically scoped variables, such as LOCALs and GLOBALs.
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