Function MemvarBlock() Foundation

Creates a set/get code block for PRIVATE or PUBLIC variables.

MemvarBlock( <cMemVarName> ) --> cMemVarBlock
<cMemVarName> is a character string which contains the name of the PRIVATE or PUBLIC variable the code block is to access.

The return value of MemvarBlock() is a code block which will access a dynamic memory variable when it is executed. The code block cannot access variables declared LOCAL or STATIC. If a variable with the name <cMemVarName> does not exist when MemvarBlock() is called, NIL is returned.


The code block function MemvarBlock() creates a code block to access PRIVATE or PUBLIC variables. The variable name must be known at runtime when the call to MemvarBlock() occurs. When the code block is evaluated, it returns the value of the memory variable. If a value is passed to the code block, the value is assigned to the variable.

// The example illustrates how a code block created with MemvarBlock() 
// works when it is evaluated with and without an argument. 

   MEMVAR cPrivate, cPublic 
   LOCAL bBlock1 , bBlock2 

   PRIVATE cPrivate := "PRIVATE variable" 
   PUBLIC  cPublic  := "PUBLIC variable" 

   bBlock1 := MemvarBlock( "cPrivate" ) 
   bBlock2 := MemvarBlock( "cPublic"  ) 

   ? Eval( bBlock1 )              // result: PRIVATE variable 
   ? Eval( bBlock2 )              // result: PUBLIC variable 

   ? Eval( bBlock1, "James" )     // result: James 
   ? Eval( bBlock2, "Bond"  )     // result: Bond 

   ? cPrivate                     // result: James 
   ? cPublic                      // result: Bond 



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.