Click or drag to resize

IsMethod Function

Check whether a particular method can be sent to an object.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.08
Syntax
 FUNCTION IsMethod(
	oObject AS Object,
	symMethod AS STRING
) AS LOGIC
View Source

Parameters

oObject
Type: Object
An object.
symMethod
Type: String
The method name, specified without parentheses.

Return Value

Type: Boolean
TRUE if the specified method is defined for the class of the specified object; otherwise, FALSE.
Remarks
Examples
This example uses IsMethod() to check whether an object is capable of making sounds:
X#
CLASS Animal
        EXPORT sound, weight
METHOD Init(s, w) CLASS Animal
        sound := s
        weight := w
METHOD Speaks CLASS Animal
        QOut(sound)
CLASS Programmer
        EXPORT language
METHOD Init(lang) CLASS Programmer
        language := lang
METHOD Speaks CLASS Programmer
        QOut(language)
        QOut("Hello World")
        QOut(Chr(7))
Function Start()
        LOCAL dog AS Animal
        LOCAL hacker AS Programmer
        dog := Animal{"Bark Bark!", 50}
        hacker := Programmer{"VO"}
        IF IsMethod(dog, #Speaks)
                dog:Speaks()        // Says Bark Bark
        ENDIF
        IF IsMethod(hacker, #Speaks)
                                                // Says VO, Hello World, rings a bell
                hacker:Speaks()        
        ENDIF
See Also