| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- unit Main;
- interface
- uses
- DragDrop,
- DropSource,
- DragDropFile,
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, ExtCtrls, ComCtrls;
- type
- TForm1 = class(TForm)
- Panel1: TPanel;
- Label1: TLabel;
- Panel2: TPanel;
- ButtonClose: TButton;
- DropFileSource1: TDropFileSource;
- ListView1: TListView;
- procedure ButtonCloseClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- public
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.DFM}
- procedure TForm1.ButtonCloseClick(Sender: TObject);
- begin
- Close;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- var
- path: string;
- sr: TSearchRec;
- res: integer;
- NewItem : TListItem;
- begin
- // Fill listview with list of files in current directory...
- path := ExtractFilePath(Application.ExeName);
- res := FindFirst(path+'*.*', 0, sr);
- try
- while (res = 0) do
- begin
- if (sr.Name <> '.') and (sr.Name <> '..') then
- begin
- NewItem := Listview1.Items.Add;
- NewItem.Caption := LowerCase(path+sr.Name);
- end;
- res := FindNext(sr);
- end;
- finally
- FindClose(sr);
- end;
- end;
- procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- var
- i: integer;
- begin
- // If no files selected then we can't drag.
- if (Listview1.SelCount = 0) then
- exit;
- // Wait for user to move cursor before we start the drag/drop.
- if (DragDetectPlus(TWinControl(Sender).Handle, Point(X,Y))) then
- begin
- // Delete anything from a previous drag.
- DropFileSource1.Files.Clear;
- // Fill DropSource1.Files with selected files from ListView1.
- for i := 0 to Listview1.Items.Count-1 do
- if (Listview1.items.Item[i].Selected) then
- DropFileSource1.Files.Add(Listview1.items.Item[i].Caption);
- // Start the dragdrop.
- DropFileSource1.Execute;
- end;
- end;
- end.
|