Function IsMemberVar() Foundation

Checks if an object has a particular member variable

Syntax
IsMemberVar( <oObject>, <cVarName>, [<nAttributes>] ) --> lExist
Parameters
<oObject>
<oObject> is the object which is tested for the member variable <cVarName>.
<cVarName>
<cVarName> is a character string containing the symbolic identifier of a member variable.
<nAttributes>
<nAttributes> is used to check if a member variable is declared with attributes restricting visibility or assignment rights. Constants listed in the following tables can be used. They are defined in CLASS.CH. Multiple attributes are specified by adding the corresponding constants.
Constants for member variable visibility
Constant Equivalent in the class declaration
CLASS_HIDDEN HIDDEN:
CLASS_PROTECTED PROTECTED:
CLASS_EXPORTED *) EXPORTED:
  1. Default
Constants for member variable assignment rights
Constant Equivalent in the class declaration
VAR_ASSIGN_HIDDEN VAR <cVarName> ASSIGNMENT HIDDEN
VAR_ASSIGN_PROTECTED VAR <cVarName> ASSIGNMENT PROTECTED
VAR_ASSIGN_EXPORTED *) VAR <cVarName> ASSIGNMENT EXPORTED
  1. Default
Constants for member variable types
Constant Equivalent in the class declaration
VAR_INSTANCE VAR <cVarName>
VAR_CLASS CLASS VAR <cVarName>
VAR_CLASS_SHARED CLASS VAR <cVarName> SHARED
If <nAttributes> is not specified, the function searches only for exported member variables with global assignment rights (CLASS_EXPORTED + VAR_ASSIGN_EXPORTED).
Return

The return value is .T. (true) if the object has the member variable <cVarName>, otherwise it returns .F. (false).

Description

The function IsMemberVar() is used to check if an object has a particular member variable. This is especially useful for objects of derived classes or dynamically created classes, or when accessing member variables with the macro operator. Together with IsMethod(), :className() and :isDerivedFrom(), IsMemberVar() offers a complete set of possibilities for analyzing objects at runtime.

Examples
Accessing instance variables with the macro operator

// In the example, a user defined function which is capable of 
// returning the value of any member variable is programmed. 

PROCEDURE Main 
   LOCAL oTB := TBrowse():new( 1, 2, 22, 78 ) 
   LOCAL oGet:= Get():new( 10, 33 ) 

   ? MemberValue( oTB, "nBottom" )  // result: 22 

   ? MemberValue( oGet,"row" )      // result: 10 

RETURN 

FUNCTION MemberValue( oObj, cVarName ) 
   LOCAL xRet 

   IF IsMemberVar( oObj, cVarName ) 
      xRet := oObj:&cVarName. 
   ENDIF 

RETURN xRet 
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.