Drop Files Components

   
Release: 5.0.5
Date: 11 January 2014
Delphi Compatibility:
D1 D2 D3 D4 D5 D6 D7 D2005 D2006 D2007 D2009 D2010 DXE DXE2 DXE3 DXE4
Red LED Red LED Grey LED Grey LED Grey LED Grey LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED Green LED

Overview

Problems with Vista and later
There are issues with the way drag and drop is handled in Windows Vista and later. Please see below for more information.

The Drop Files Components pack includes three components that support drag and drop from Windows Explorer along with subsidiary components that can filter dropped files.

The components are:

TPJDropFiles
A container control that catches files dragged and dropped onto its client area or the client area of child controls.
TPFormDropFiles
A non-visual component that catches files dragged and dropped from Explorer onto the form that contains the component.
TPJCtrlDropFiles
A non-visual component that catches files dragged and dropped from Explorer onto an associated control.
TPJExtFileFilter
A file filter component that filters files according to their extension.
TPJWildCardFileFilter
A file filter component that filters files according to a DOS-style wild card.
TPJFileFilter
An abstract base class for file filter components. Developers should derive any new filter components from this class.

Some design time assistance is provided by component and property editors.

Key features of TPJDropFiles, TPJCtrlDropFiles and TPJFormDropFiles are:

  • An OnDropFiles event is triggered when files are dropped.
  • The names of dropped files are made available through the Files array property. For convenience, the name of the first such file is also stored in the FileName property.
  • The list of dropped files can be configured to include only files, only folders or all files and folders.
  • Dropped folders can be recursed so that all the files and sub-folders in each of the dropped folders are listed.
  • Filters can be applied to the dropped files and folders. This is done either by linking to a filter component (see above) or by handling the OnFileFilter event and deciding which files and folders to pass through the filter in the event handler.
  • The mouse co-ordinates where the files were dropped can be retrieved, as can a reference to any control under the mouse cursor at the time.
  • The OnBeforeDrop event can be used to perform pre-processing before the files are actually dropped.
  • The IsFolder array property tells if the equivalent item from Files array is a file or a folder.
  • The owning window can be brought to the front when files are dropped.
  • Some design time assistance is provided by component and property editors.

The components are compatible with 32 bit and 64 bit Windows VCL targets. They do not work with FireMonkey.

Documentation

The components are documented online.

There is also an FAQ page hosted on the DelphiDabbler Wiki.

Users of Delphi 7 and earlier can also make use of the help file that is included in the download. It integrates with the Delphi 3-7 help system. The help file is a WinHelp file and therefore does not work on Windows Vista or later unless WinHelp has been downloaded and installed. See Microsoft Knowledge Base Article KB917607 for further information.

How the components work

TPJDropFiles notifies Windows that it accepts file drop operations by using the DragAcceptFiles API call. It then responds to WM_DROPFILES messages sent by Windows whenever files are dropped on its window.

TPJFormDropFiles and TPJCtrlDropFiles act in a similar way to TPJDropFiles except that they subclass an associated window and respond to WM_DROPFILES messages on the window's behalf. TPJFormDropFiles subclasses its owner form while TPJCtrlDropFiles subclasses the window of an associated TWinControl. These last components derive from a common abstract base class.

For further information about how to handle files dropped on an application from Explorer, please see my article "How to catch files dragged and dropped on an application from Explorer".

Problems with Windows Vista and Later

For security reasons in Windows Vista, drag/drop is disallowed between windows with different security permissions. This means that applications that processes drag and drop may not be able to receive files dragged and droppped from another window if the security permissions are not compatible.

Since this enforced by the operating system please do not report the problem as a bug.

Demo Programs

The source code for two demo programs is included:

  1. The main demo program exercises all three drop files components and the filter components.
  2. A program that demonstrates how to use TPJCtrlDropFiles with frames.

The demo projects require Delphi 7 or later.

Feedback & Queries

If you find any bugs or want to suggest a new feature please report them using the Issue Tracker.

Click the Create Ticket button to create a ticket then complete the form giving as much information as possible. Please note: this issue tracker is shared among all the projects in the DelphiDabbler Code Library, so please make sure you enter dropfiles in the Project edit box. You should also choose Defect in the Type drop down list to report a bug or Enhancement to request a new feature.

If you have created a bug fix or have implemented a new feature please attach a zip file to your ticket that contains your source code.

Should you have any queries about using the components please read the documentation and FAQ.

If you can't find an answer in the documentation then post a message in the discussion group.

Please do not email me or use the contact page to report bugs, ask for new features or to find out how to use the components.
I'm afraid I have very limited time available to support the code library, and can't guarantee I'll find time for personalised advice.