From Xojo Documentation
Used to determine the class of a particular object reference.
result = object IsA object class
|result||Boolean||Any container expecting a boolean value.|
|object||Object||Any object name.|
|object class||Object class||Any object class or class interface.|
If object is of type class, then IsA returns True; if not, it returns False. If object is Nil, then IsA returns False. The IsA operator returns True for the object's own class as well as the super class from which that class was derived, all the way to the Object class. IsA will report that all classes ultimately derive from Object.
Remember that object must always be a class instance, not just a variable with the class of the type. For example, this code always returns False because d is not an instance:
' Returns False because d is not an instance
If d IsA Dictionary Then
Instead you create an instance like this:
' Returns True because d an instance of Dictionary
If d IsA Dictionary Then
The IsA operator returns True for the object's own class as well as the super class from which that class was derived, all the way to the Object class. IsA will report that all classes ultimately derive from Object.
For example, suppose you create a subclass of TextField called SecureTextField, that disables the Cut and Copy commands in the Edit menu. If TextField1 is an instance of SecureTextField, the tests:
both return True.
You use the IsA operator to cast objects. With the IsA operator, you test whether an object is of a specific subclass and, if it is, cast it as that type to do something specific with it.
Here is an example that uses a For loop to cycle through all the controls in a window to test whether each control is a TextField. If it is, it casts the control, gets its name and the value of its Text property, and assigns the contents of the TextField to the field in a database table named fieldname.
// Check if the control is a TextField
If Self.Control(i) IsA TextField Then
// Cast the control to a TextField in order to access the Text property
TextField(Self.Control(i)).Text = "Found You!"
As you can see, the code is generic since it uses no references to specific TextFields or databases.
A second example of casting uses the Window function to get the frontmost window and then using IsA to determine which what kind of window it is (i.e., Window1, Window2) and then casts it as that type to access something specific about the window
The IsA operator works in Select...Case statements like this (in the Action event of a PushButton):
Case IsA PushButton
MsgBox("I'm a PushButton.")
Case IsA TextField
You also use the IsA operator in connection with a class interface. If a custom class implements a particular class interface, then IsA return True. For example, if you create a class interface, myClassInterface, and custom control classes subclassed from the Label, TextFields, TextAreas, and Canvas classes all implement myClassInterface, then the IsA operator will return True for each such test.
In this way, you can write generic code that examines all controls in a window to determine whether each control implements a particular class interface. If it does, then you can execute any methods of the class interface.
For example, if you wrote a class interface called FontInterfaceManger that updates the font displayed by a control using a method called UpdateTheFont, you use code such as this to call the method only for the controls in a window that implement the FontInterfaceManager class interface. This following example, which can be the Action event handler of a PushButton in a window, examines all the controls in the window and calls the UpdateTheFont method for those controls that implement the class interface FontInterfaceManager.
If Self.Control(i) IsA FontInterfaceManager Then
This example uses the IsA operator to determine if the variable p is a PushButton object. If it is, the caption property is assigned "OK".