473,846 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
sp********@arca derestoration.c om (real email address)
http://www.arcaderestoration.com
Nov 21 '05 #1
1 1641
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
sp********@arca derestoration.c om (real email address)
http://www.arcaderestoration.com
"Brien King" <sp********@arc aderestoration. com> wrote in message
news:OL******** ******@tk2msftn gp13.phx.gbl...
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
sp********@arca derestoration.c om (real email address)
http://www.arcaderestoration.com

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
12205
by: James Marshall | last post by:
I need to detect the type of an object, more than just "object" as typeof gives us. I'm writing a general handler that accepts a variety of objects and properties, and acts accordingly depending on which type of object it gets. Object types to be handled include windows, documents, locations, links, images, layers, and so on. I'm using Mozilla, but I'm looking for a platform-independent solution. I know of four potential approaches to...
10
5276
by: fabioppp | last post by:
Hi there, g++'s typeof is a very useful feature! Will it never be in the Standard? Is there any compliant way to implement it? If I mean a function template returning a type, maybe is this impossible? What's about g++'s typeof implementation; how does it work internally? Thank.
7
42578
by: Bennett Haselton | last post by:
Is there any way to find a string representing an object's class, which will work in Internet Explorer 6? "typeof" doesn't work -- it returns "object" for all objects: x = window.open('http://www.yahoo.com/'); alert(typeof x); And I found this page: http://www.mozilla.org/js/language/js20-2002-04/core/expressions.html
3
5252
by: TD | last post by:
This code doesn't work. Every posting I can find suggests that it should. If TypeOf controlname Is DTPicker then do something here End If I am using the Date Time Picker control and wish to use TypeOf to determine if the controlname is indeed a Date Time Picker control.
4
299
by: Eric | last post by:
I need to do the following but it doesn't compile if(typeof(listBox1.Items) == typeof(string)){ return; } typeof(listBox1.Items) doesn't work at all. My listBox has 2 types of items in them and I need to know what kind of item a user clicked on so I can use it for drag and drop
3
950
by: Alberto | last post by:
Can somebody tell me why this typeof doesn't work? foreach (Control myControl in Controls) if (typeof(myControl) == "TextBox") ((TextBox)myControl).Text = string.Empty; Thank you very much
11
5627
by: Jason Kendall | last post by:
Why doesn't the new "IsNot" operator work in conjunction with 'Typeof'?
20
9326
by: effendi | last post by:
I am testting the following code in firefox function fDHTMLPopulateFields(displayValuesArray, displayOrderArray) { var i, currentElement, displayFieldID, currentChild, nDisplayValues = displayValuesArray.length; for (i=0; i<nDisplayValues; i++) {
20
21798
by: rkk | last post by:
Hi, Is there an equivalent typeof macro/method to determine the type of a variable in runtime & most importantly that works well with most known C compilers? gcc compiler supports typeof() macro, but the same code is not getting compiled in solaris forte compiler and in microsoft VS 2003 compiler. I tried something like below:
0
9879
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9725
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10976
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10640
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7050
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5714
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5906
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4111
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.