Click or drag to resize

FieldBlock Function

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

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION FieldBlock(
	cFieldName AS STRING
) AS Codeblock
Request Example View Source

Parameters

cFieldName
Type: String
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 cFieldName.
If omitted, the code block retrieves the value of cFieldName.

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 cFieldName does not exist in the current work area, FieldBlock() 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 FieldBlock() 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 := FieldBlock("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 FieldBlock() to a code block created using the macro operator. Note that using FieldBlock() avoids the speed and size overhead of the macro operator:
X#
1// Set-Get block defined using macro operator
2cbSetGet := &("{|SetVal| If(SetVal == NIL,;
3                     FName, FName := SetVal)}")
4// Set-Get block defined using FieldBlock()
5// cbSetGet created here is the functional
6// equivalent of cbSetGet above
7cbSetGet := FieldBlock("FName")
See Also