Skip over navigation

Drop Files Components

Components that handle drag and drop of files

Version 5.0.5
Released 2014-01-11
Platforms Win32 & Win64
Framework VCL
Compatibilty Delphi 7 and later

Overview

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 source code for two demo programs is included:

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

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. The last two 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".

Get The Code

You can download the latest version of the Drop Files Components directly from SourceForge as dd-dropfiles-5.0.5.zip.

Download v5.0.5

The Drop Files Components source code is hosted in the ddablib/dropfiles GitHub repository. You can git clone or fork the repository as required.

Installation

The Drop Files Components are supplied in a zip file. Before installing you need to extract all the files from the zip file, preserving the directory structure. The following files will be extracted:

  • PJDropFiles.pas – component source code.
  • PJDropFiles.dcr – component palette glyphs.
  • PJDropFilesDsgn.pas – property editors and component registration source code.
  • PJDropFilesDsgn.dfm – property editor form.
  • ReadMe.htm – read-me file.
  • ChangeLog.txt – component's change log.
  • MPL-2.txt – the Mozilla Public License v2.0.
  • Documentation.URL – short-cut to the component's online documentation.
  • PJDropFiles.hlp – component help file that integrates with the Delphi 3-7 OpenHelp system. Deprecated
  • PJDropFiles.als – a-link keyword file for integration with the Delphi 6 or 7 OpenHelp system. Deprecated

In addition to the above files you will find the source code of the two demo projects in the Demo\1 and Demo\2 sub-directories.

You may now install the components into the Delphi IDE. To do this, the files PJDropFiles.pas, PJDropFiles.dcr, PJDropFilesDsgn.pas and PJDropFilesDsgn.dfm should be added to a design time package. If you need help doing this see here.

Documentation

The Drop Files Components are comprehensively documented online here

The project's change log can be viewed here.

A read-me file (ReadMe.htm) is included in the project download.

A legacy WinHelp help file is included in the download that can only be integrated with the IDE in Delphi 7 and earlier. This article explains how to do it.

This help file is deprecated and is no longer being updated. The last update was in the v5.0.3 release. The help file will be removed from any future release.

WinHelp is an optional download for Windows Vista through to Windows 8.1 and can't be installed at all on Windows 10 and later.

There is also an FAQ.

Feedback & Queries

If you find any bugs or want to suggest a new feature please report them using the Drop Files Components issue tracker.

If you have created a bug fix or have implemented a new feature please open a pull request for it.

Should you have any queries about using the components please read the documentation and/or FAQ. If you can't find an answer in the documentation then post a message in the discussion group.

License

The Drop Files Components are open source. They are copyright © 1998-2014 by Peter Johnson. The source code is made available under the terms of the Mozilla Public License v2.0. All relevant trademarks are acknowledged.