TypeOf Problem, why doesn't this work?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brien King

    TypeOf Problem, why doesn't this work?

    Ok, I have three classes (The example here is extremely simplified to
    illustrate the problem) like this:

    Public Class A
    Public Sub DoSomething(ByV al myClass)
    If TypeOf myClass IS A Then
    '
    ' Never Enters here....
    '
    End If
    End Sub
    End Class

    Public Class B
    Inherits Class A
    End Class

    Public Class C
    Inherits Class B
    End Class

    Then I use Class C to do some work like this:

    dim myClassC1 as New C
    dim myClassC2 as New C
    C1.DoSomething( C2)

    The problem is, is that when DoSomething is executed on the Base class, the
    TypeOf check fails and says that the object passed in is NOT of the type A.
    I was under the impression that the TypeOf would return True if the object
    was the specific class I was asking about or any class that derived from it.

    Since C derives from B which derives from A, C IS a type of A. Is this
    incorrect? Or am I missing something?

    Any help would be greatly appreciated!

    Brien King
    spammehere@arca derestoration.c om (real email address)



  • Brien King

    #2
    Re: TypeOf Problem, why doesn't this work?

    Ok, as a follow up to this, I discovered what I was doing wrong and I am
    posting a reply to my own message here so that others bennifit from my
    mistake.

    The Code below actually DOES work (I didn't test it, I just created it to
    illustrate the issue I was having). However, the problem I was running into
    didn't have to do with TypeOf, it actually was a problem with my Drag & Drop
    code. I had created a base class that implemented a bunch of Drag & Drop
    options.

    When I started my Drag & Drop I did:

    Me.DoDragDrop(M e, DragDropEffects .Move)

    Which is fine for the current class. However, in derived classes, this is
    problematic as the e.GetData(GetTy pe(MyBaseClass) ) will return NULL for
    anything other than the specific type you are looking for. This is why my
    "If TypeOF e.GetData(GetTy pe(MyBaseClass) ) IS MyBaseClass" returned FALSE.
    Since e.GetData(GetTy pe(MyBaseClass) ) returned NOTHING, TypeOf determined
    that NOTHING is not a type of my base class. Which is True :-)

    So what I had to do is create a new wrapper Class that I called
    TDraggedClass that was simply a container for my class. Then I could do:

    tempObj = e.GetData(GetTy pe(TDraggedClas s))

    and that would return my wrapper class. If it didn't then I knew it wasn't
    something I was expecting and could just exit. If it returned a valid
    object then I could ask it for the object it had inside of it and my TypeOf
    would then work as expected.

    Brien King
    spammehere@arca derestoration.c om (real email address)



    "Brien King" <spammehere@arc aderestoration. com> wrote in message
    news:OLJczdktEH A.1308@tk2msftn gp13.phx.gbl...[color=blue]
    > Ok, I have three classes (The example here is extremely simplified to
    > illustrate the problem) like this:
    >
    > Public Class A
    > Public Sub DoSomething(ByV al myClass)
    > If TypeOf myClass IS A Then
    > '
    > ' Never Enters here....
    > '
    > End If
    > End Sub
    > End Class
    >
    > Public Class B
    > Inherits Class A
    > End Class
    >
    > Public Class C
    > Inherits Class B
    > End Class
    >
    > Then I use Class C to do some work like this:
    >
    > dim myClassC1 as New C
    > dim myClassC2 as New C
    > C1.DoSomething( C2)
    >
    > The problem is, is that when DoSomething is executed on the Base class,
    > the TypeOf check fails and says that the object passed in is NOT of the
    > type A. I was under the impression that the TypeOf would return True if
    > the object was the specific class I was asking about or any class that
    > derived from it.
    >
    > Since C derives from B which derives from A, C IS a type of A. Is this
    > incorrect? Or am I missing something?
    >
    > Any help would be greatly appreciated!
    >
    > Brien King
    > spammehere@arca derestoration.c om (real email address)
    > http://www.arcaderestoration.com
    >[/color]


    Comment

    Working...