wideman-one 
Last edit: 05-03-17 Graham Wideman

Delphi

OLE Drag and Drop Delphi Overview
Article created: 98-06-26
Major revision: 98-07-28

Orientation

There are plenty of reasons for you to want your application to be able to accept   drops from other applications. Often you may just want to accept or source a file or files, but at other times you want to be able to accept or source other items, and here's where the fun starts.  If you've looked into how to do that, you'll have run into the steep learning curve associated with getting into Microsoft's COM/OLE system.

Well, thankfully, a number of authors have recently tackled that topic, and laid down most of the path for us to follow. To really nail down the concepts, and see how OLE drag-and-drop works,  I decided to build some demo apps that would:

Version applicability: This article applies to (and the software has been tested with) Windows NT 4 (SP3) and Windows 95. It uses techniques that have applied certainly since 1995, hence should work with NT 3.5x, and who knows, might even work with NT 5 and Windows 98!. The code is for Delphi 3, I expect it to work in Delphi 4, and it may also work with Delphi 2.

Drag and Drop Variations

There are at least three different drag-and-drop variations to think about:

Within-app drag-and-drop: Your app manages this any way you like, using the various drag and drop events provided with Delphi TControls. Since you have control over both ends of the transaction, you can move any kind of data you like.   You could use COM in the process, but you certainly don't have to.

Between-app drag-and-drop: The source and destination applications must each provide certain COM objects to manage the drag-time behavior, and to pass the data from one app to the other.  If you try to read the "raw" OLE documentation on how to do this, it looks daunting.  Fear not, Delphi makes it somewhat easier, and the third-party books, demos, and the demo I describe here show the way.  

Between-app drag-and-drop, Files Only: So-called CF_HDROP (clipboard-format, handle for dropping files). Accepting dropped files is a limited but often-useful subset of general drop-accept capability, so Windows provides a way to do this without requiring your app to know about COM.  Jim Mischel covers this in "High Performance Delphi 3"... but later concludes (and it looks about right to me) "What I found most surprising about [the OLE] drop target implementation is that it's less complicated than the [files-only implementation]". 

Pieces to Master

There are two main things to master:

With that said, proceed to try out the demo applications, or go to the Theory page... see Contents page.

Resources/References

Copyright Status

Please feel free to distribute or publish this article and associated code, provided some note of credit for me remains attached. Permission is also granted to include this article on CDROM collections, again provided credit remains attached. Thanks!


Go to:  [Back to Drag and Drop Contents]   wideman-one