Status

Latest version: 5.2
Released: 17 aug 2010
Download

The Drag and Drop Component Suite is a freeware VCL component library that enables your Delphi and C++Builder applications to support COM based drag and drop and integrate with the Windows clipboard.

The drag and drop system that is built into the VCL, is limited in that it only supports drag and drop within the same application. If you need to drag data from your application to other applications (e.g. Word, Explorer or Outlook), or if you need to be able to accept data dropped from other application (e.g. the Explorer), you have to use COM based drag and drop. COM based drag and drop is an integral and very important part of the Windows user interface and the Drag and Drop Component Suite makes it very easy to leverage all the features of COM based drag and drop in your own Delphi and C++Builder applications.

Every drag and drop operation involves two objects: A drop source and a drop target. The drop source provides the data to be dragged, and the drop target accepts the dragged data.
Likewise there are basically two sets of components in the Drag and Drop Component Suite; Drop source components and drop target components. Most of the source and target components are specialized to handle just one type of data, but a few of the components supports a wider range of data types or are completely generic.

In addition to the drag and drop components, the Drag and Drop Component Suite also includes components that can be used to build Windows Shell Extensions. While these components aren’t all related to Drag and Drop, they benefit from the Drag and Drop Component Suite framework and allow you to write Windows Shell Extensions with very little code. But most important; I had a lot of fun writing them :-).

Features

  • Freeware with full source code included.
  • Enables COM drag-and-drop of any kind of data between applications.
  • Copy, Move and Link operations.
  • Clipboard Copy, Cut and Paste support.
  • Support and implement advanced features such as Delete-on-paste and Optimized Move.
  • Drag image support.
  • Supports both Ansi and Unicode data formats, regardless of the version of Delphi used.
  • Supports asynchronous transfer. Both on the source and target side.
  • Automatic scrolling of the target window during the drag operation.
  • Relatively simple to derive custom drag-and-drop components to support other data formats.
  • Extensive, context sensitive help file and detailed demo applications.
  • Implements the IDropSource, IDropTarget, IDataObject and IAsyncOperation interfaces.
  • Compatible with Delphi 5 through Delphi 2010.

Components

The Drag and Drop Component Suite contains the following components:

Drop Sources Drop Targets
  • TDropFileSource Enables you to drag files and shortcuts from your application to other applications.
  • TDropTextSource Enables you to drag text from your application to other applications.
  • TDropBMPSource Enables you to drag bitmaps from your application to other applications.
  • TDropURLSource Enables you to drag URLs from your application to other applications.
  • TDropPIDLSource Enables you to drag PIDLs (files, folders, shell objects) from your application to other applications.
  • TDropEmptySource A basic drop source component that does not support any data formats on its own. Can be extended with support for any data format through the use of a TDataFormatAdapter component.
  • TDropFileTarget Enables your application to accept files and shortcuts dropped on it from other applications.
  • TDropTextTarget Enables your application to accept text dropped on it from other applications.
  • TDropBMPTarget Enables your application to accept bitmaps dropped on it from other applications.
  • TDropMetaFileTarget Enables your application to accept meta files dropped on it from other applications.
  • TDropURLTarget Enables your application to accept URLs dropped on it from other applications.
  • TDropComboTarget Enables your application to accept files, shortcuts, text, URLs, meta files, and bitmaps dropped on it from other applications. The component is basically all the above components rolled into one.
  • TDropImageTarget Enables your application to accept meta files, and bitmaps dropped on it from other applications. The component is basically the TDropBMPTarget and the TDropMetaFileTarget components rolled into one.
  • TDropPIDLTarget Enables your application to accept PIDLs (files, folder, shell objects) dropped on it from other applications.
  • TDropEmptyTarget A basic drop target component that does not support any data formats on its own. Can be extended with support for any data format through the use of a TDataFormatAdapter component.
Shell Extensions Additional
  • TDropHandler Implements the necessary interfaces required to build Drop Handler shell extensions.
    A Drop Handler shell extension is used to turn file classes (e.g. all files with a specific extension) into drop targets.
  • TDragDropHandler Implements the necessary interfaces required to build DragDrop Handler shell extensions.
    A Drop Handler shell extension is used to extend the popup menu which is displayed by the shell when a file is dragged with the right mouse button.
  • TDropContextMenu Implements the necessary interfaces required to build Context Menu Handler shell extensions.
    A Context Menu Handler is used to extend the shell popup menu which is displayed when a file is right-clicked.
  • TDataFormatAdapter Used to extends source or target components with support for arbitrary clipboard formats.
  • TDropDummy Helper component used to display drag images.

License

Creative Commons License
This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 Unported License.

Requirements

The library has been tested with the following versions of Delphi:

D1 D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010
Fail Fail Fail Fail Pass Pass Pass Unknown Pass Pass Pass Pass

If you can confirm compatibility with any of the untested versions of Delphi (or C++ Builder for that matter), please let me know and I will update the table.

C++ Builder

I have done absolutely no testing with C++ Builder so I don’t know if the code works with it or not. That said, according to feedback I have received, the current release should work with C++ Builder.

Download

download
Download: The Drag and Drop Component Suite v5.2
Version: 5.2
Updated: 17 August, 2010
Size: 505.61 KB
Notes: Includes component source and demo applications.
Downloads: 38,594


Old versions

Old versions can be found on the downloads page.

Installation

  1. If you are using a previous version of The Drag and Drop Component Suite, uninstall that version first.
  2. Unzip the package to a folder of your choice.
  3. In the Packages folder, find the design time package that matches your version of Delphi. Open it in Delphi, Compile and Install.
  4. Locate the Library sub-folder that matches your version of Delphi. Add it to the Delphi library search path.
  5. Optional: Add the Source folder to the Delphi browsing path.

Uninstallation

  1. Open Delphi and uninstall the Drag and Drop Component Suite design time package.
  2. Remove the Library folder from the Delphi library search path.
  3. Remove the Source folder from the Delphi browsing path.
  4. Locate the folder where you installed The Drag and Drop Component Suite and delete that folder.

Change log

Changes since version 4.2:

  • Version 5.2 (17-aug-2010)
      Bug fixes:

    • The DOF files of the example projects has been fixed so they will be imported correctly in Delphi 2007 and Delphi 2010. Delphi 2009 user are on their own I’m afraid.
    • Fixed memory leaks in TRawClipboardFormat.
    • Fixed bug in TRawClipboardFormat that caused it to stop functioning after first use.
    • TDropContextMenu now properly supports nested context menus.
    • An error could occur in a drop target if a drag operation was attempted on the target while an existing asynchronous transfer was in progress on it.
      Improvements:

    • DragDetectPlus has been improved to make it possible to use it with popup menus and TTreeView:
      • It does not remove mouse messages from the message queue unless a drag has been detected (i.e. the function returns True).
      • It works with both left and right mouse button.
    • The (undocumented) functionality that disables the IDE’s drop targets during debug (in order to avoid an IDE deadlock) has been improved so it can recover from the debugee being reset.
    • The handling of TCustomDropTarget.Enabled has been improved.
    • Drop target AutoScroll feature
      • The default scroll zone calculation has been moved to the public ResetScrollZone method.
      • The existing auto scroll logic has been extended to call ResetScrollZone in both DragEnter and DragOver. DragOver will not call ResetScrollZone if a custom scroll zone has been specified through the NoScrollZone property thus if the user specifies a custom scroll zone in OnDragEnter then the scroll zone will not be automatically reset in DragOver.
    • The Clear/Destroy logic in TOutlookDataFormat and TStorageDataFormat has been improved based on user feedback.
    • TFileContentsStreamClipboardFormat and TFileContentsStorageClipboardFormat now handles both Ansi and Unicode data. Among other things this fixes problems with Outlook drop targets.
      Other changes:

    • TRawClipboardFormat.CopyFromStgMedium and CopyToStgMedium methods are now functions that return a boolean. The return values indicates if the method was able to perform the requested operation.
    • The TDropFileSource.Files and MappedNames properties are no longer published. They are now public properties.
  • Version 5.1 (29-jan-2010)
      Bug fixes:

    • Missing paths in package project files for Delphi 6, Delphi 2006 and Delphi 2007.
    • Missing Output and search path in a few demo applications.
    • The OutlookDemo example application hung or crashed on exit if a message attachment had been opened.
    • The MakeRTF function in the DragDropText unit failed to compile with some versions of Delphi.
    • PIDLs was not generated automatically from Unicode filenames. This caused the “link” drag operation to fail in most cases.
    • DragDetectPlus no longer eats right-click mouse messages.
      Improvements:

    • TargetAnalyzer example application
      The application now performs an asynchronous drag and can be aborted with the [Esc] key. This change was made to be able to break out of Thunderbird and Firefox’s run-away drag loops.
    • SourceAnalyzer example application
      • Error handling improved.
      • The application can now optionally prefetch data at the time of drop, instead of at the time the clipboard format is selected in the list.
      • The application now verifies if the media types offered by the drop source can actually be read from the drop source. An amazing number of applications specify more media type and data formats than they actually support - or doesn’t specify the ones they do support. The prize for most funky behaviour goes to Mozilla Thunderbird 3; It does both.
    • OutlookDemo example application
      Handling of attachments simplified.
    • ExtractDemo example application
      The application now extract files On-Demand (OnGetData event) instead of when the data is dropped (OnDrop event). This change was made to handle application that require the files to be physically present when ever they query the drop source for the file names.
      Other changes:

    • The SourceDemo example application no longer demonstrates the use of a popup menu.
      This change was made because TListView’s internal mouse message handling makes it impossible to handle right-click correctly.
  • Version 5.0.20091206 (6-dec-2009)
      New features:

    • Support for Delphi 2010.
    • Six new examples:
      • Outlook Source
        Demonstrates how to drag messages from your application to Outlook.
      • RTF Target
        Demonstrates how to receive RTF text. E.g. from Word, WordPad or the TRichEdit control.
      • Target Analyzer
        Analyzes how a drop target interacts with a drop source. Can be used to determine which data formats a drop target can accept.
      • Unicode
        Demonstrates drag/drop of Unicode text and file names to and from your application. The example works unchanged with all supported versions of Delphi.
      • WM_DROPFILES
        Demonstrates the old, non-COM based, way of handling files dropped from Explorer - just for completeness.
      • TreeViewTarget
        Demonstartes accepting or rejecting a drop based on position within drop target.
    • Added TCustomDropTarget.Enabled property.
      The Enabled property specifies if the drop target control can accept dragged data. Setting Enabled to False will cause the drop target to reject all drops without further action.
    • The TMessages class (used for Outlook drag/drop) now support sessions. This can be (and is) used to work around the various quirks in Outlook’s interface reference counting mechanism.
      Bug fixes:

    • Work around for bug in Outlook Express.
      Drop target now asks drop source (e.g. Outlook Express) for each supported data format in turn instead of all at once.
    • Work Around for bug in Bluesoleil Shell Integration.
      We now query the drop source for supported data formats before asking for data.
    • TAnsiStringClipboardFormat.GetClipboardFormat has been implemented.
    • TCustomDropTarget.PasteFromClipboard no longer clears the data after the OnDrop event has fired.
    • Fixed bug in TClipboardFormat.GetData that caused drop targets to reject data after first drop.
    • Fixed Ansi/Unicode bug in TTextDataFormat that mainly affected TDropTextTarget.
    • All Ansi/Unicode conversion hints and warnings has been removed.
    • The default property value of TDropComboTarget.OptimizedMove and TDropFileTarget.OptimizedMove is now declared correctly.
    • The Shell IL function imports are now compatible with C++ Builder.
    • TStorageDataFormat now support both Ansi and Unicode File Group Descriptors regardless of the version of Delphi used.
      Improvements:

    • Unicode string list redesigned.
      The solution for Unicode string lists, used for file name lists, that was introduced in version 4.2 has been replaced with a solution that does not require class helpers. This means that the same solution is now employed across all supported versions of Delphi.
      The new Unicode string list does not descend from TStrings but is Assign/AssignTo compatible with it.
      All properties, that previously depended on TWideStringList for Unicode support, now use the new TUnicodeStringList instead.
    • The DragDetectPlus function now leave mouse click messages (WM_xBUTTONDOWN, WM_xBUTTONUP, etc) in the message queue.
      This change was made to allow drop source controls to use popup menus.
    • URL properties are now of type AnsiString.
    • The MakeRTF utility function now support Unicode strings and generate proper RTF formatted text.
    • The Text data format now support RTF text by default (i.e. it registers the TRichTextClipboardFormat class).
    • The design-time package files have been renamed for Delphi 2005 and later.
  • Version 5.0.20090208 (8-feb-2009)
    • Completed Delphi 2009/Unicode migration.
    • Back ported to Delphi 5, 7 and 2007.
      DragDrop unit:

    • Clipboard format registration has been redesigned to remove various bad designs.
    • Fixed harmless memory leak.
      DropSource unit:

    • TCustomDropSource.OnGetDragImage event added.
    • Fixed resource leak.
    • Added work around for broken asynchronous transfer in Windows Shell.
    • Added work around for deadlock caused by drag over Delphi IDE while debugging.
    • Fixed various minor problems with optimized move.
      DragDropFormats unit:

    • The TFileGroupDescriptor*ClipboardFormat, TFileContents*ClipboardFormat and TVirtualFileStreamDataFormat classes has been moved to the DragDropFile unit.
    • The T*TextClipboardFormat classes has been moved to the DragDropText unit.
    • Fixed bug in CreateIStreamFromIStorage and CreateIStorageOnHGlobal which primarily affected drag/drop from Outlook.
    • Fixed leak in TFileGroupDescriptorCustomClipboardFormat.
      DragDropFile unit:

    • Fixed misspelling of “FileGroupDescriptor” - woops :-(
    • TFilenameClipboardFormat has been renamed TAnsiFilenameClipboardFormat.
    • TFilenameWClipboardFormat has been renamed TUnicodeFilenameClipboardFormat.
    • TFilenameClipboardFormat is now an alias for the native (ansi or unicode) format.
    • TFilenameMapClipboardFormat has been renamed TAnsiFilenameMapClipboardFormat.
    • TFilenameMapWClipboardFormat has been renamed TUnicodeFilenameMapClipboardFormat.
    • TFilenameMapClipboardFormat is now an alias for the native (ansi or unicode) format.
    • TFileGroupDescriptorClipboardFormat has been renamed TAnsiFileGroupDescriptorClipboardFormat.
    • TFileGroupDescriptorWClipboardFormat has been renamed TUnicodeFileGroupDescriptorClipboardFormat.
    • TFileGroupDescriptorClipboardFormat is now an alias for the native (ansi or unicode) format.
      DragDropText unit:

    • Text scrap functionality is no longer enabled by default.
    • TTextClipboardFormat has been renamed TAnsiTextClipboardFormat
    • TCustomTextClipboardFormat has been renamed TCustomAnsiTextClipboardFormat
    • TCustomWideTextClipboardFormat has been renamed TCustomUnicodeTextClipboardFormat
    • TTextClipboardFormat is now an alias for the native (ansi or unicode) format.
    • TDropTextTarget, TDropTextSource and TTextDataFormat now keeps string data data in the source format and only converts between unicode and ansi on demand.
    • The old Text property of TDropTextTarget, TDropTextSource and TTextDataFormat is now named AnsiText.
    • The new Text property of TDropTextTarget, TDropTextSource and TTextDataFormat now returns the native string format.
    • The RichText, OEMText, CSVText and HTML properties of the TDropTextTarget, TDropTextSource and TTextDataFormat classes are no longer supported and have been removed.
      DragDropContext unit:

    • Major rewrite of the TDropContextMenu component.
    • Added TDropContextMenu.OnPrepareMenu event.
    • Added TDropContextMenu.FolderPIDL and TDropContextMenu.Folder properties.
    • Added support for accelerator keys in owner-draw sub menu items.
    • Fixed support for ownerdraw top level menu items.
      DragDropHandler unit:

    • The TDragDropHandler.GetFolderPIDL function has been replaced with the FolderPIDL property.
      Note that the component owns and manages the life time of the returned PIDL.
    • Added support for cascaded menus.
      DragDropInternet unit:

    • TURLClipboardFormat has been renamed TAnsiURLClipboardFormat
    • TURLWClipboardFormat has been renamed TUnicodeURLClipboardFormat
    • TURLClipboardFormat is now an alias for the native (ansi or unicode) format.
    • The Title property of TDropURLTarget, TDropURLSource and TURLDataFormat is now a Unicode string.
      DragDropPIDL unit:

    • PIDLs are no longer stored and manipulated as strings.
      DropComboTarget unit:

    • TDropMultiTarget is no longer supported.
      Use TDropComboTarget or the adapter components instead.
  • Version 5.0.20080514 (14-may-2008)
    • Added const directive to interface parameters.
    • Prepared for Delphi 2009/Unicode.
    • PIDLs are no longer stored and manipulated as strings.
    • Deprecated Netscape data formats.
    • Added TFileGroupDescriptorCustomClipboardFormat as common ancestor for TFileGroupDescriptorClipboardFormat and TFileGroupDescriptorWClipboardFormat.
    • Back ported to Delphi 5 and Delphi 7.

FAQ - Frequently Asked Questions

  • Positive  Negative
    Rating: +6

    When dragging a file from my application to the Explorer, how can I determine the folder where the file is dropped?

    In short, you can’t.

    You must understand that the drag/drop API works the same for all applications that uses it, and the Explorer is just like any other application. The drag/drop API provides a framework that facilitates the interaction between a drop source and the target, but since the drop target can do anything it wants with the data it receives, there is no way to communicate the destiny of the data back to the drop source in a uniform way.
    One target may chose to display the dropped data (e.g. notepad), another one to upload it to a web server (e.g. a FTP client), a third to move and rename the file (e.g. the Recycle Bin) and a fourth may chose to copy or move the file (e.g. Explorer).

    In my experience there is never any real need to know the destination of a drop to the Explorer. If you find that you do need this, you should rethink your solution. - and feel free to ask for help.

  • Positive  Negative
    Rating: +2

    What is the difference between the drop source components’ AllowAsyncTransfer property and the Execute methods’ Asynchronous parameter?

    The Execute methods Asynchronous parameter specifies if the source should perform the transfer in a thread.

    The AllowAsyncTransfer property specifies if the drop target is allowed to perform an asynchronous transfer.

    The two are completely independent. One does not have priority over the other.

    Asynchronous transfer on the source side is an “invention” of mine. It can be done even if the drop target doesn’t support, and thus doesn’t take an active part in, asynchronous transfer.

    Asynchronous transfer on the target side is a COM drag/drop feature (see IAsyncOperation in MSDN). It requires that both the source and the target support asynchronous transfer. All the Drag and Drop Component Suite components support asynchronous transfer, but apart from Windows Explorer few applications has implemented the feature.

  • Positive  Negative
    Rating: +5

    What is “Optimized Move”?

    An optimized move is simply a move operation where the drop target moves the data from the source to the destination location.

    In a conventional move operation, the source and the target must cooperate in order to complete the operation. First the target makes a copy of the data at the desired location. Then, when the target has completed copying the data, it hands control back to the source who then deletes the original data. This procedure can be very inefficient because it requires two simultaneous copies of the data.

    With an optimized move, the target handles the entire move operation and signals the source that an optimized move took place upon completion.

    The Drag and Drop Component Suite supports Optimized Move on both the source and target side.