Click or drag to resize

FieldBlockSym Function

X#
Return a set-get code block for a field that is identified by a symbol.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION FieldBlockSym(
	symFieldName AS SYMBOL
) AS Codeblock
Request Example View Source

Parameters

symFieldName
Type: Symbol
A symbol that is the name of the field to which the set-get block will refer. When executed with an argument, the code block created by this function assigns the value of the argument to symFieldName.
If omitted, the code block retrieves the value of symFieldName.

Return Value

Type: Codeblock
A runtime code block (implemented as an object) that, when evaluated, sets (assigns) or gets (retrieves) the value of the given field.
If symFieldName does not exist in the current work area, FieldBlockSym() returns NULL_OBJECT.
Remarks
By default, this function operates on the currently selected work area.
It can be made to operate on an unselected work area by specifying it within an aliased expression
Note that the specified field variable does not have to exist when the code block is created but must exist before the code block is executed.
Tip Tip
Work area:
The code block returned by FieldBlockSym() sets or gets the value of the specified field in whatever work area is current when the block is run.
For example, given work areas 1 and 2, both containing field FName:
X#
1DBSetSelect(1)
2_FIELD->FName := "Kate"
3DBSetSelect(2)
4_FIELD->FName := "Cindy"
5cbFName := FieldBlockSym(#FNAME)
6DBSetSelect(1)
7? EVAL(cbFName)                        // "Kate"
8DBSetSelect(2)
9? EVAL(cbFName)                        // "Cindy"
Use FieldWBlock() to provide a set-get block for a field in a specific work area.
Examples
This example compares FieldBlockSym() to a code block created using the macro operator. Note that using FieldBlockSym() avoids the speed and size overhead of the macro operator:
X#
1// Set-Get block defined using macro operator
2cbSetGet := &("{|SetVal| If(SetVal == NIL, FName, FName := SetVal)}")
3// Set-Get block defined using FieldBlockSym()
4String2Symbol("FName")
5cbSetGet := FieldBlockSym(#FNAME)
See Also