Function FieldWBlock() Foundation

Creates a set/get code block for a field in a specific work area.

Syntax
FieldWBlock( <cFieldName>, <nWorkArea>|<cAlias> ) --> bFieldBlock|NIL
Parameters
<cFieldName>
<cFieldName> is a character string containing the name of the field whose data the code block will read or modify.
<nWorkArea>
<nWorkArea> is a positive integer specifying the work area containing the field the code block will access.
<cAlias>
Alternatively, <cAlias> can be specified for <nWorkArea>. <cAlias> is a character string containing the alias name for the work area holding the field which the code block will access.
Return

The return value of FieldWBlock() is a code block providing access to the data of a field in a specific work area when it is evaluated. If the parameter are not of the expected types then NIL is returned.

Description

The code block function FieldWBlock() creates a code block providing (when it is evaluated) read and write access to a field in the specified work area. If no value is passed to the code block when it is evaluated, the current value from the field <cFieldName> is read and returned. Otherwise, the code block writes the passed value into the field and returns this new value.

When FieldWBlock() is called, no file needs to be opened in the specified work area. However, when the code block is evaluated, the file containing the field the code block is accessing must be open. If the field <cFieldName> does not exist when the code block is evaluated, a runtime error occurs.

FieldWBlock() differs from the function FieldBlock() in that the returned code block is tied to a specific work area. If the work area is specified by a numeric value <nWorkArea>, the code block is tied to this specific work area.

If an alias name <cAlias> is passed to the function, the code block is tied to the workarea with the name <cAlias>. The resulting codeblock can access the field if the database file is closed and then reopened in another work area with the same name.

Examples
FieldWBlock()
// The example illustrates the use of the code block created 
// by FieldWBlock(). A file is opened after the creation 
// of two code blocks and then an empty work area is 
// selected. 

PROCEDURE Main 
   LOCAL bBlock1 := FieldWBlock( "LastName", 1 ) 
   LOCAL bBlock2 := FieldBlock( "LastName" ) 

   USE Customer ALIAS Cust NEW 

   ? Eval( bBlock1 )           // result: King 
   ? Eval( bBlock2 )           // result: King 

   ? Select()                  // result: 1 
   SELECT (100) 
   ? Alias()                   // result:  (null string ("")) 

   CLOSE Cust 
   USE Customer ALIAS Cust 
   ? Select()                  // result: 100 

   ? Eval( bBlock2 )           // result: King 
                               // code block uses 
                               // current area 

   ? Eval( bBlock1 )           // runtime error: code block is 
                               // tied to work area No. 1 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.