Main.pas 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. unit Main;
  2. interface
  3. uses
  4. DragDrop,
  5. DropSource,
  6. DragDropFile,
  7. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  8. StdCtrls, ExtCtrls, ComCtrls;
  9. type
  10. TForm1 = class(TForm)
  11. Panel1: TPanel;
  12. Label1: TLabel;
  13. Panel2: TPanel;
  14. ButtonClose: TButton;
  15. DropFileSource1: TDropFileSource;
  16. ListView1: TListView;
  17. procedure ButtonCloseClick(Sender: TObject);
  18. procedure FormCreate(Sender: TObject);
  19. procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  20. Shift: TShiftState; X, Y: Integer);
  21. private
  22. public
  23. end;
  24. var
  25. Form1: TForm1;
  26. implementation
  27. {$R *.DFM}
  28. procedure TForm1.ButtonCloseClick(Sender: TObject);
  29. begin
  30. Close;
  31. end;
  32. procedure TForm1.FormCreate(Sender: TObject);
  33. var
  34. path: string;
  35. sr: TSearchRec;
  36. res: integer;
  37. NewItem : TListItem;
  38. begin
  39. // Fill listview with list of files in current directory...
  40. path := ExtractFilePath(Application.ExeName);
  41. res := FindFirst(path+'*.*', 0, sr);
  42. try
  43. while (res = 0) do
  44. begin
  45. if (sr.Name <> '.') and (sr.Name <> '..') then
  46. begin
  47. NewItem := Listview1.Items.Add;
  48. NewItem.Caption := LowerCase(path+sr.Name);
  49. end;
  50. res := FindNext(sr);
  51. end;
  52. finally
  53. FindClose(sr);
  54. end;
  55. end;
  56. procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
  57. Shift: TShiftState; X, Y: Integer);
  58. var
  59. i: integer;
  60. begin
  61. // If no files selected then we can't drag.
  62. if (Listview1.SelCount = 0) then
  63. exit;
  64. // Wait for user to move cursor before we start the drag/drop.
  65. if (DragDetectPlus(TWinControl(Sender).Handle, Point(X,Y))) then
  66. begin
  67. // Delete anything from a previous drag.
  68. DropFileSource1.Files.Clear;
  69. // Fill DropSource1.Files with selected files from ListView1.
  70. for i := 0 to Listview1.Items.Count-1 do
  71. if (Listview1.items.Item[i].Selected) then
  72. DropFileSource1.Files.Add(Listview1.items.Item[i].Caption);
  73. // Start the dragdrop.
  74. DropFileSource1.Execute;
  75. end;
  76. end;
  77. end.