Click or drag to resize

FieldBlockSym Function

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.08
Syntax
 FUNCTION FieldBlockSym(
	symFieldName AS SYMBOL
) AS Codeblock
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#
DBSetSelect(1)
_FIELD->FName := "Kate"
DBSetSelect(2)
_FIELD->FName := "Cindy"
cbFName := FieldBlockSym(#FNAME)
DBSetSelect(1)
? EVAL(cbFName)                                                // "Kate"
DBSetSelect(2)
? 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#
// Set-Get block defined using macro operator
cbSetGet := &("{|SetVal| If(SetVal == NIL, FName, FName := SetVal)}")
// Set-Get block defined using FieldBlockSym()
String2Symbol("FName")
cbSetGet := FieldBlockSym(#FNAME)
See Also