How do you detect the type of an object ?

I have an array of variants. Inside that array I have instances of different classes, and I need to analyse each one of them.
How can I get the type of an element, and if it contains an instance of a particular class ?

For example, let’s assume that we have three classes named Tom, Dick and Harry. I could initialize an array of variants this way:

    Dim listOfObjects() As Variant

    listOfObjects.Append(New Tom())
    listOfObjects.Append(New Dick())
    listOfObjects.Append(New Harry())

In this case, how can I detect if listOfObject(2) contains an instance of Tom, Dick or Harry ?

In VB.NET I could write something like this:

    If listOfObjects(2).getType() Is GetType(Tom) Then
    Else If listOfObject(2).getType() Is GetType(Dick) Then
    End If

But I don’t know how to write a similar piece of code in Xojo.

Thank you

if listOfObjects(2) IsA Tom then ... ElseIf listOfObjects(2) IsA Dick then ,,, End If

[quote=18441:@Tim Hare]if listOfObjects(2) IsA Tom then ... ElseIf listOfObjects(2) IsA Dick then ,,, End If [/quote]

Thank you very much, this is exactly what I was looking for

I like Select cases also for this, seems like a nice clean syntax:

Select Case listOfObjects(2) Case IsA Tom ... Case IsA Dick ... Case IsA Harry ... Case Else ... End Select

variants kind of force you to write type unsafe code AND also force you to write piles of “isA …” kinds of code

if each member of that array implemented a common interface then the array could be typed as that interface and each member could still be a different base class type AND the interface type

you get type safety & reasonably generic code at the same shot