Function IsMethod() Foundation

Checks if an object has a particular method

Syntax
IsMethod( <oObject>, <cMethodName>, [<nAttributes>] ) --> lExist
Parameters
<oObject>
<oObject> is the object which is tested for the method <cMethodName>.
<cMethodName>
<cMethodName> is a character string containing the symbolic identifier of a method.
<nAttributes>
<nAttributes> is used to check if a method variable is declared with particular attributes. 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 method visibility
Constant Equivalent in the class declaration
CLASS_HIDDEN HIDDEN:
CLASS_PROTECTED PROTECTED:
CLASS_EXPORTED *) EXPORTED:
  1. Default
Constants for method types
Constant Equivalent in the class declaration
METHOD_INSTANCE METHOD <cMethodName>
METHOD_CLASS CLASS METHOD <cMethodName>
If <nAttributes> is not specified, the function searches only for exported methods and does not distinguish between instance and class methods (CLASS_EXPORTED).
Return

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

Description

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

Examples
Executing methods with the macro operator

// In the example, a user defined function which is capable of 
// calling any method of an arbitrary object is programmed. 

FUNCTION CallMethod( oObj, cMethodName, xParam ) 
   LOCAL xRet 

   IF IsMethod( oObj, cMethodName ) 
      xRet := oObj:&cMethodName.( xParam ) 
   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.