Introspection bug?

I have a situation where I need to know if an object is is a base class or a subclass. Looking at the docs for Introspection.IsSubclass of I thought “GREAT exactly what I need!!!”

But it was not as I found out the hard way!

This code obviously illustrates the issue:

[code] Dim C as New Class1
Dim D As New Class1

Dim InfoC As Introspection.TypeInfo = Introspection.GetType©
Dim InfoD As Introspection.TypeInfo = Introspection.GetType(D)

If InfoC.IsSubclassOf(InfoD) Then
MsgBox infoC.Name + " is a subclass of "+ InfoD.Name
Else
MsgBox infoC.Name + " is NOT a subclass of "+ InfoD.Name
End if[/code]

The msg Shows “Class 1 is a subclass of class1” Which is literally false as Class1 is not a subclass if Class1!!!

I consider this a bug… but i know others often feel differently. So is this a bug that needs to be fixed or something that only needs to be documented in the language reference.

The workaround is to check if type info.BaseType is NIL

Me too.

Won’t work for all cases. I would check for the class name too:

[code]Dim Object1 as New Class1
Dim Object2 As New Class1

Dim Info1 As Introspection.TypeInfo = Introspection.GetType(Object1)
Dim Info2 As Introspection.TypeInfo = Introspection.GetType(Object2)

If Info2.IsSubclassOf(Info1) And Info2.FullName <> Info1.FullName Then
MsgBox info2.Name + " is a subclass of "+ Info1.Name
Else
MsgBox info2.Name + " is NOT a subclass of "+ Info1.Name
End[/code]

I might be misunderstanding, but aren’t Object1 and Object both the same class? For Object2 to be a subclass of Object1 wouldn’t you need to create a new class based on Class1?

That’s what they’re saying. Object2 is not a subclass of Object1, they’re the same class, so TypeInfo.IsSubclassOf should be returning false but the bug is it’s returning true.

ahh… My bad… I read the wrong part wrong :wink:

I just tried this on my Win 7, Xojo 2014R3 (I haven’t tried 3.1) and it seems to be correct. I used your exact code and I’m getting the message that “Class1 is NOT a subclass of Class1”.

Could the problem be OS specific?

[quote=156830:@Dale Arends]I just tried this on my Win 7, Xojo 2014R3 (I haven’t tried 3.1) and it seems to be correct. I used your exact code and I’m getting the message that “Class1 is NOT a subclass of Class1”.

[/quote]

That is VERY Strange… i get is a subclass on OSX 10.9.5 as well as for Windows 7 on Parrallels…

This is in a Desktop project in the default windows’s open event.

Has anybody else actually RUN my code above? If so what do you see and where are you running it?

Thanks

  • karen

Xojo 2014r3
Mac OS X 10.10.1

I get the same results as you “is a subclass”

FYI I’m on 2014r3.1

This may be Xojo version related though I think introducing such a bug in point release would be unlikely.

Also got the same results with Xojo 2014r2.1

Tested Code in Open Event of Window and a PushButton:

Class1 is not a Subclass of Class1

Xojo 3.1
OSX 10.10.1 Yosemite

Different people are getting different results… Strange!!!

Maybe you should post a sample project to make sure everybody is using the same code.

OS X 10.10.1, I get “Class1 is a subclass of Class1” using both 2014r3.1 and 2011r3 (yes, 2011) using Karen’s original code in both a pushbutton action event and the window open event.

Don’t Think I need to post a project:

I tried it with a framework Class:

[code] Dim A as new RectShape
Dim B as New RectShape

Dim InfoA As Introspection.TypeInfo = Introspection.GetType(A)

Dim InfoB As Introspection.TypeInfo = Introspection.GetType(B)

MsgBox InfoA.Name + " Is a subclass of " + InfoB.Name + " : " + Str(InfoA.IsSubclassOf(InfoB))

MsgBox InfoA.Name + " Is a subclass of " + InfoA.Name + " : " + Str(InfoA.IsSubclassOf(InfoA))
[/code]

In both cases I get : “RectShape is a subclass of RectShape : True”

I get True on Windows 7 in both Xojo 2014r3.1 and RS 2010r5. It’s not a new issue and it does seem like a bug to me, too.

I get the same result with your code, which does not seem right. But then, how come Björn Dohle finds different ? Maybe he used a different code ? If this is, it would be nice to know what he used to get the appropriate response.

clean Desktop project…

Put Karens code in open Event of Window and inserted a clean Class1 with one Property… (also tested it without a property inside the class)

no Problem here… also with another laptop with Mountain Lion and XOJO 2014 3.1

[quote=156918:@Björn Dohle]Dim C as New Class1
Dim D As New Class1

Dim InfoC As Introspection.TypeInfo = Introspection.GetType©
Dim InfoD As Introspection.TypeInfo = Introspection.GetType(D)

If InfoC.IsSubclassOf(InfoD) Then
MsgBox infoC.Name + " is a subclass of "+ InfoD.Name
Else
MsgBox infoC.Name + " is NOT a subclass of "+ InfoD.Name
End if[/quote]

This is real strange. I did the same, and both in the Open event of the window or in the button action I get Class1 is a subclass of Class1 . 2014R3.1, Yosemite 10.10.1.