MemVarBlockSym Function | |
Return a set-get code block for a given memory variable.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax FUNCTION MemVarBlockSym(
symMemvarName AS SYMBOL
) AS Object
public static Object MemVarBlockSym(
Symbol symMemvarName
)
Request Example
View SourceParameters
- symMemvarName
- 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.
Remarks
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 |
---|
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 (&).
|
Examples
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
3cbSetGet := &("{|setVal|;
4 If(setVal = NIL, var, var := setVal)}")
5
6
7cbSetGet := MemVarBlock("var")
See Also Reference
MemVarBlockSym(Symbol)