Function WorkSpaceEval() Foundation

Evaluates a code block in all used work areas of a work space

Syntax
WorkSpaceEval( <bAreaBlock>, [<nWorkSpace>] ) --> nProcessed
Parameters
<bAreaBlock>
The argument <bAreaBlock> must be a code block. It is evaluated in all used work areas of the work space specified with <nWorkSpace>.
<nWorkSpace>
Constants from DMLB.CH must be used for the optional argument <nWorkSpace>. It specifies the work space in which WorkSpaceEval() is executed. The following table lists all valid constants:
Constants to specify the work space
Constant Description
DB_ZEROSPACE WorkSpaceEval() is executed in the Zero space
DB_WORKSPACE *) WorkSpaceEval() is executed in the current work space
  1. default
Return

The function returns a numeric value that indicates the number of work areas where the code block <bAreaBlock> is evaluated.

Description

The function WorkSpaceEval() evaluates a code block in all used work areas of a work space. It is used, for example, to set, save or restore the environment within all work areas. If DB_ZEROSPACE is specified, information about work areas pending in the Zero space can be retrieved, which normally is not possible without a prior call to DbRelease().

Examples
Determine which work areas are used

// In the example, the function UsedAreas() is programmed. It 
// returns an array containing the numbers of all used work areas. 

FUNCTION UsedAreas() 
   LOCAL aUsed := {} 

   WorkSpaceEval( {|| AAdd( aUsed, Select() ) } ) 

RETURN aUsed 
Save the current state of all work areas

// The example demonstrates how to save and restore the current 
// state of all work areas. The user-defined function SaveWorkSpace() 
// saves and RestWorkSpace() restores the state of the work areas. 

********************** 
FUNCTION SaveWorkSpace 
   LOCAL aSaved := {} 

   WorkSpaceEval( {|| AAdd( aSaved, SaveWorkarea() ) } ) 

RETURN { aSaved, Select() } 


********************* 
FUNCTION SaveWorkarea 
RETURN  { ; 
   {  Select()   , {|x| DbSelectArea(x)} }, ; 
   {  OrdNumber(), {|x| OrdSetFocus(x) } }, ; 
   {  Recno()    , {|x| Dbgoto(x)      } }  } 


******************************** 
FUNCTION RestWorkSpace( aSaved ) 

   AEval( aSaved[1] , ; 
          {|a| AEval( a, {|aa| Eval( aa[2], aa[1] ) } ) } ) 

RETURN DbSelectArea( aSaved[2] ) 

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.