MemVarBlock Function
|
|
Return a set-get code block for a given memory variable.
Namespace:
XSharp.RT
Assembly:
XSharp.RT (in XSharp.RT.dll) Version: 2.24 GA
Syntax FUNCTION MemVarBlock(
cMemvarName AS STRING
) AS Object
public static Object MemVarBlock(
string cMemvarName
)
Request Example
View SourceParameters
- cMemvarName
- 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.
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 (&).
|
Remarks 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.
|
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