473,387 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

OK to assign an IDataObject reference to a DataObject variable

I do the following:

Note that I'm returning and interface because GetDatObject returns an
interface.

Public Shared Function GetContents() As DataObject

Dim ClipboardDataO As IDataObject = Clipboard.GetDataObject()

'assign an IDataObject reference to a DataObject variable

Return ClipboardDataO

End Function

End Class

elsewhere I do

Dim DataO As DataObject = GetContents()

That is I store the reference to the returned interface into an object of
class DataObject (not IDataObject)

It appears to work OK but now I noticed what I did and wonder why it is OK
to assign an IDataObject reference to a DataObject variable

Could you add some understanding the above?

Suppose I use DataO.GetHashCode (there is no IDataObject.GetHashCode) What
happens?

Thanks


Dec 26 '05 #1
2 2178
What you are doing is entirely correct, and by design. It works because the
DataObject returned by Clipboard.GetDataObject() implements the IDataObject
interface.

Given your code, you might see fit to change

Public Shared Function GetContents() As DataObject

to

Public Shared Function GetContents() As IDataObject

and, subsequently

Dim DataO As DataObject = GetContents()

to

Dim DataO As IDataObject = GetContents()

since that is what you are creating internally, but it does depend on how
you go on to use the return value from this function.

HTH

Charles
" **Developer**" <RE*************@a-znet.com> wrote in message
news:Oz**************@TK2MSFTNGP14.phx.gbl...
I do the following:

Note that I'm returning and interface because GetDatObject returns an
interface.

Public Shared Function GetContents() As DataObject

Dim ClipboardDataO As IDataObject = Clipboard.GetDataObject()

'assign an IDataObject reference to a DataObject variable

Return ClipboardDataO

End Function

End Class

elsewhere I do

Dim DataO As DataObject = GetContents()

That is I store the reference to the returned interface into an object of
class DataObject (not IDataObject)

It appears to work OK but now I noticed what I did and wonder why it is OK
to assign an IDataObject reference to a DataObject variable

Could you add some understanding the above?

Suppose I use DataO.GetHashCode (there is no IDataObject.GetHashCode) What
happens?

Thanks


Jan 3 '06 #2
Thanks for the insight
"Charles Law" <bl***@nowhere.com> wrote in message
news:eX**************@TK2MSFTNGP14.phx.gbl...
What you are doing is entirely correct, and by design. It works because
the DataObject returned by Clipboard.GetDataObject() implements the
IDataObject interface.

Given your code, you might see fit to change

Public Shared Function GetContents() As DataObject

to

Public Shared Function GetContents() As IDataObject

and, subsequently

Dim DataO As DataObject = GetContents()

to

Dim DataO As IDataObject = GetContents()

since that is what you are creating internally, but it does depend on how
you go on to use the return value from this function.

HTH

Charles
" **Developer**" <RE*************@a-znet.com> wrote in message
news:Oz**************@TK2MSFTNGP14.phx.gbl...
I do the following:

Note that I'm returning and interface because GetDatObject returns an
interface.

Public Shared Function GetContents() As DataObject

Dim ClipboardDataO As IDataObject = Clipboard.GetDataObject()

'assign an IDataObject reference to a DataObject variable

Return ClipboardDataO

End Function

End Class

elsewhere I do

Dim DataO As DataObject = GetContents()

That is I store the reference to the returned interface into an object of
class DataObject (not IDataObject)

It appears to work OK but now I noticed what I did and wonder why it is
OK to assign an IDataObject reference to a DataObject variable

Could you add some understanding the above?

Suppose I use DataO.GetHashCode (there is no IDataObject.GetHashCode)
What happens?

Thanks



Jan 3 '06 #3

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

Similar topics

4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
0
by: DraguVaso | last post by:
Hi, I made some application (VB.NET 2005) based on classes in Windows Forms. I made a new Class Library Project and copied all of my classes and modules in it, to make a DLL that I could import...
1
by: Jinlin | last post by:
Does anyone know how to serialize a dataObject. Is it possible? What I try to do in my application is to allow user drag and drop objects onto a toolbox type of thing, and try to preserve these...
3
by: JP | last post by:
I have an app that represents ShellFolder Items as a visual element (listview item, etc). The code correctly performs Drag&Drop operations EXCEPT in the case when the item being dragged is from a...
7
by: **Developer** | last post by:
Although the code is VB I believe the question is OOP I tried the VB NG but no answer. I suspect the c# programmer is more apt to be aware of these kinds of subtleties so I', trying here. I do...
4
by: Bob Staheli | last post by:
The .Net DataObject class implements the COM/OLE IDataObject interface , so how do I get it. I have tried this, but it does not work : // Declare the COM/OLE IDataObject interface public...
3
by: nicolas.hilaire | last post by:
Hi group, when using unmanaged class with my managed app, I've seen errors when including (for example) <windows.h>. One of theses erros is : IDataObject : ambiguous symbol error I've seen...
42
by: blisspikle | last post by:
I tried closely copying some code that I found on this group for assigning a type at runtime, but I cannot get it to work. Can someone see what is wrong with my logic? Thanks, Private Sub...
0
by: =?ISO-8859-1?Q?=22Ro=DFert_G=2E_Schaffrath=22?= | last post by:
Sorry for the cross-posting. I am having a hard time trying to classify exactly what group this question would apply to. I had posted an earlier message to...
3
by: =?ISO-8859-1?Q?Norbert_P=FCrringer?= | last post by:
Hello, I've got a recursive data model, where the root object gets a certain event handler: DataObject root = new DataObject(); root.DataObjectCreated += new...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.