Drop Files Components
|Date:||11 January 2014|
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:
- A container control that catches files dragged and dropped onto its client area or the client area of child controls.
- A non-visual component that catches files dragged and dropped from Explorer onto the form that contains the component.
- A non-visual component that catches files dragged and dropped from Explorer onto an associated control.
- A file filter component that filters files according to their extension.
- A file filter component that filters files according to a DOS-style wild card.
- 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.
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.
The source code for two demo programs is included:
- The main demo program exercises all three drop files components and the filter components.
- 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
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.
If you can't find an answer in the documentation then post a message in the discussion group.