wideman-one 
Last edit: 98-06-29 Graham Wideman

Delphi

OLE Drag and Drop, and a demo "Drop Explorer" for Delphi
Article created: 98-06-26

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 a file or files, but at other times you want to be able to accept 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 a little app that would:

Contents

If you are reading this page off my web site, then download all source code, executables and these pages here: GWDrop.zip (if reading from CD or hard-drive, you already got this zip and expanded it, so the link is disabled.)

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 application, or go to the Theory page... see the contents listing above.

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:  wideman-one