Click or drag to resize

Functions.FieldBlock Method

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.18
 FUNCTION FieldBlock(
	cFieldName AS STRING
) AS Codeblock
Request Example View Source


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.
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:
2_FIELD->FName := "Kate"
4_FIELD->FName := "Cindy"
5cbFName := FieldBlock("FName")
7? EVAL(cbFName)                    // "Kate"
9? EVAL(cbFName)                    // "Cindy"
Use FieldWBlock() to provide a set-get block for a field in a specific work area.
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:
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