Drop Files Components


Contents


Description

This unit provides two components that can handle files dragged and dropped from Windows Explorer, along with two additional helper components that can optionally be used to filter the files dropped:

TPJDropFiles

TPJDropFiles provides a window which can accept files dragged and dropped from Windows Explorer. The window takes on the appearance of its parent window, although anything drawn on the parent's canvas is obliterated.

The control can contain child components (in a similar way to TPanel components). Files dropped over any such child component are accepted by the parent TPJDropFiles component. The TPJDropFiles component can be aligned with the form on which it is placed using the Align property.

When files are dropped over this component the OnBeforeDrop event is first triggered. The dropped files are then processed and dropped folders and optionally recursed. Files and folders can be filtered using either by handling the OnFileFilter event or by using the component in association with one of special "filter" components (see below). Once the files have been processed and filtered the OnDropFiles event is triggered. The names of the files are recorded in the Files property and the number of files is held in the Count property.

The point at which the files were dropped is given by the DropPoint property (in coordinates relative to the control). The DropControl property identifies any child control that was under the mouse cursor when the files were dropped.

The window containing the control can optionally be given the focus when files are dropped.

TPJFormDropFiles

TPJFormDropFiles is a non-visual component that enables the form where it is dropped to accept files dragged and dropped from Explorer. Whenever files are dropped anywhere on the form's window, the OnDropFiles event is triggered.

As with TPJDropFiles files can be filtered and the number and names of dropped files, the drop coordinates and any control under the mouse cursor can be found.

The Filters

There are two filter components provided that can be used with either of the above components. They are:


Compatibility

This component is compatible with Delphi 3 to 7 and has been tested with all but v5.


Installation

Installation with Delphi 3 to 7

In these instructions $(DELPHI) is to be taken to represent the path where the appropriate version of Delphi was installed. For example, if you have Delphi 7 installed on the default installation path then $(DELPHI) is equivalent to \Program Files\Borland\Delphi7.

  1. Unzip the component's .zip into a folder of your choice, preserving the directory structure.
  2. Copy the files PJDropFiles.pas and PJDropFiles.dcr to where you wish to install into Delphi. This will probably be a sub-folder of the $(DELPHI)\lib folder.
  3. Install the unit's components and property editor into the palette by chosing the Component | Install Component menu option to display the Install Component dialog box. Then:
  4. You can now delete PJDropFiles.pas from the place where you copied it if you wish (but ensure that the .dcu file is not deleted). The component will appear on a palette called DelphiDabbler. The other code in the unit can be made available simply by use-ing the unit in your projects. You can move the components to a different palette as required.
  5. The simplest way to install the help file is to use my Component Help Installer Expert. To install manually, proceed as follows:
  6. The supplied demo programs can be loaded into Delphi and compiled and run as required.

Known Issues

There was a bug in release 2.0 where length of strings containing names of dropped files was being set incorrectly. This was fixed from release 2.0.1.

In v3.0 and v3.1 the DropControl property did not always return the correct control - this was been fixed in v3.2

There was a small memory leak in all release 3 versions. This has been fixed in release 4.0


Update History

Release 4.0 of 12 Apr 2004
PJDropFiles v4.0 of 12 Apr 2004

Release 3.2 of 09 Feb 2004
PJDropFiles v3.2 of 09 Feb 2004

Release 3.1 of 29 Jul 2003
PJDropFiles v3.1 of 29 Jul 2003

Release 3.0 of 27 Oct 2002
PJDropFiles v3.0 of 27 Oct 2002

Release 2.0.1 of 13 May 2001
PJDropFiles v2.0.1 of 13 May 2001

Release 2.0 of 29 Apr 2001
PJDropFiles v2.0 of 29 Apr 2001

Release 1.1.1a of 28 Nov 1999
DrpFiles v1.1.1 of 09 Apr 1999

Release 1.1.1 of 10 Jul 1999
DrpFiles v1.1.1 of 09 Jul 1999

Un-released
DrpFiles v1.1 of 22 Oct 1998

Un-released
DrpFiles v1.0 of 15 May 1998


License & Disclaimer

This component is copyright © P.D.Johnson, 1998-2004. It is released under the Mozilla Public License:

Version: MPL 1.1

The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/.

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

The Original Code is Drop Files Components.

The Initial Developer of the Original Code is Peter Johnson (http://www.delphidabbler.com/).

Portions created by the Initial Developer are Copyright © 1997-2003 Peter Johnson. All Rights Reserved.

Contributor(s):


About the Author

I'm Peter Johnson - a hobbyist programmer living in Ceredigion in West Wales, UK. I write mainly in Delphi. My programs are available for download on my web-site: http://www.delphidabbler.com/.

I can be contacted via the website.