473,659 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetDa taObject()

'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.GetHashCo de (there is no IDataObject.Get HashCode) What
happens?

Thanks


Dec 26 '05 #1
2 2185
What you are doing is entirely correct, and by design. It works because the
DataObject returned by Clipboard.GetDa taObject() 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******** ******@TK2MSFTN GP14.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.GetDa taObject()

'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.GetHashCo de (there is no IDataObject.Get HashCode) What
happens?

Thanks


Jan 3 '06 #2
Thanks for the insight
"Charles Law" <bl***@nowhere. com> wrote in message
news:eX******** ******@TK2MSFTN GP14.phx.gbl...
What you are doing is entirely correct, and by design. It works because
the DataObject returned by Clipboard.GetDa taObject() 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******** ******@TK2MSFTN GP14.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.GetDa taObject()

'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.GetHashCo de (there is no IDataObject.Get HashCode)
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
12567
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)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
0
386
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 afterwarths in Windows Forms applciations. The problem is that I get several errors indication that some methods aren't declared or defined when I try to build the project...
1
3556
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 objects (DataObject) when user quit the application, so they could drop they back to an editor leter. I can successfully serialize the inner data of dataObject after GetData(formatType), but by converting to a specific format type, I lose some...
3
4325
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 Virtual Folder. The problem is that the DragSource is my app, not the Virtual Folder, and therefore the IDataObject interface is clueless about how to get the data. My understanding is that I need to obtain and use the IDataObject Interface of...
7
2111
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 the following: Note that I'm returning and interface because GetDatObject returns an interface.
4
5961
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 interface IOleDataObject {
3
7809
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 somewhere that to avoid this error, i've to remove all "using namespace XXXXX" from .h, and move it to .cpp.
42
1933
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 Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim s As String s = "blah"
0
2782
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 microsoft.public.dotnet.framework.windowsforms trying to find a way to access the lindex member of the FORMATETC structure for a CFSTR_FILECONTENTS callback request under C#. After some experimenting I was able to come up with the following code snippet that receives the callback...
3
1850
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 DataObjectEventHandler(OnDataObjectCreated); Now the DataObject has a collection of sub data objects with following
0
8428
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
8748
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...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
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
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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
1978
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.