Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1073469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:59:47+00:00 2026-05-16T20:59:47+00:00

I have a BaseClass, a DerivedClass1 and a DerivedClass2 from a third party library.

  • 0

I have a BaseClass, a DerivedClass1 and a DerivedClass2 from a third party library. DerivedClass1 and DerivedClass2 both inherit from BaseClass.

There’s a ContainerClass, from the same library, with a member variable ActiveItem, which can be of DerivedClass1 or DerivedClass2, so it is declared as BaseClass.

I want to know if ActiveItem is of DerivedClass1, as it can change in runtime without notice.

If I do

 Dim isDerivedClass1 as boolean = TypeOf(oject.ActiveItem) Is DerivedClass1 

then I get a compile time error, telling me that ActiveItem can never be of DerivedClass1 type.

I have tried several combinations of GetType and TypeOf but it doesn’t seem possible to check this. I have also tried to declare an auxiliary DerivedClass1 variable and comparing their types, but haven’t got any luck either.

Is there any workaround?
I guess I could do it with Reflection, but seems really overkill.

Edit:
The following code doesn’t compile in vs2005 SP1.

Public Class Base
    Public x As Integer
End Class
Public Class Derived1
Inherits Base
    Public y As Integer
End Class
Public Class Derived2
Inherits Base
    Public z As Integer
End Class
Public Class Unrelated
    Public var As Base
End Class


Public Class Form1
    Public Sub Test(ByVal obj As Unrelated)
        Dim tst As Boolean
        tst = TypeOf obj Is Derived1
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim obj As New Unrelated
        obj.var = New Derived1
        Test(obj)
    End Sub
End Class

Edit:
It seems that the original problem was a fault in my side. I was checking against the wrong type (those silly third part libraries…)
However, I’m still trying to find the error in the code above.

Edit:
Again, my fault. I’m checking the Unrelated type against Base.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:59:48+00:00Added an answer on May 16, 2026 at 8:59 pm

    You code seems to be almost exactly right.

    I’ve done this, which works fine:

    Dim isDerivedClass1 As Boolean = TypeOf oject.ActiveItem Is DerivedClass1
    Dim isDerivedClass2 As Boolean = TypeOf oject.ActiveItem Is DerivedClass2
    

    Have I missed something?

    EDIT: I think you just missed the var property in your edited code.

    Public Sub Test(ByVal obj As Unrelated)
        Dim tst As Boolean
        tst = TypeOf obj.var Is Derived1
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class named baseClass. From this class I inherit a class names
I have a baseclass, Statement , which several other classes inherit from, named IfStatement
I have a UserControl that has a BaseClass object as a public member. Right
I have this code for example public class BaseClass {} public class DerivedClass1 :
Is there anyway to have a sort of virtual static member in C++? For
I have a class e.g. DerivedClass that inherits from a base class e.g. BaseClass.
for example we have BaseClass myBaseObject InheritedClass myInheritedObject and 2 overloaded methods void Do(BaseClass
Suppose I have a baseclass called IMessage, and lots of derived message classes. In
I have an abstract baseclass with some protected members, but no abstract members: internal
I have two classes: BaseClass : NSObject AdvanceClass : BaseClass And in AdvanceClass i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.