Click or drag to resize

IsMethod Function

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

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

Parameters

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

Return Value

Type: Logic
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#
 1CLASS Animal
 2    EXPORT sound, weight
 3CONSTRUCTOR(s, w)
 4    sound := s
 5    weight := w
 6METHOD Speaks CLASS
 7    QOut(sound)
 8END CLASS
 9
10CLASS Programmer
11    EXPORT language
12CONSTRUCTOR(lang)
13    language := lang
14METHOD Speaks
15    QOut(language)
16    QOut("Hello World")
17    QOut(Chr(7))
18END CLASS
19Function Start()
20    LOCAL dog AS Animal
21    LOCAL hacker AS Programmer
22    dog := Animal{"Bark Bark!", 50}
23    hacker := Programmer{"VO"}
24    IF IsMethod(dog, #Speaks)
25        dog:Speaks()    // Says Bark Bark
26    ENDIF
27    IF IsMethod(hacker, #Speaks)
28                        // Says VO, Hello World, rings a bell
29        hacker:Speaks()    
30    ENDIF
See Also