Recent

Author Topic: Initiating Drag/Drop files from Lazarus Application  (Read 2438 times)

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Initiating Drag/Drop files from Lazarus Application
« on: October 19, 2018, 07:44:01 am »
I am displaying a list of files in a TDBGrid.  I want to be able to drag a list of selected records from my grid and drop them onto a program which accepts WM_DROPFILES.

My environment is Windows (Windows 7 64bit).

It's been far too long since I did any drag/drop, I've never done it inter-application (certainly OnEndDrag doesn't seem useful) and I've never done it with WM_DROPFILES.  Does anyone have any pointers? 

Ta

PS I'm currently ploughing through MS docs like https://docs.microsoft.com/en-us/windows/desktop/shell/dragdrop... Hoping not to have to implement from scratch...
« Last Edit: October 19, 2018, 07:46:39 am by Mike.Cornflake »
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

ASerge

  • Hero Member
  • *****
  • Posts: 1408
Re: Initiating Drag/Drop files from Lazarus Application
« Reply #1 on: October 20, 2018, 03:53:46 pm »
I want to be able to drag a list of selected records from my grid and drop them onto a program which accepts WM_DROPFILES.
My environment is Windows (Windows 7 64bit).
An example of using attachment:
In the new project add the TMemo component to the form, fill in its lines with the full file names and add the code with the event:
Code: Pascal  [Select]
  1. procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
  2.   Shift: TShiftState; X, Y: Integer);
  3. begin
  4.   if DragDropCopyComplete(Memo1.Lines) then
  5.     Caption := 'Dropped';
  6. end;
Then, at run time, drag Memo to some directory in Windows Explorer.

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: Initiating Drag/Drop files from Lazarus Application
« Reply #2 on: October 22, 2018, 08:07:17 am »
Many thanks @ASerge.  I've downloaded your code, and it appears to be spot on.  It'll be a few days before I get a chance to investigate, but I'm confident.  Much appreciated.
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1248
Re: Initiating Drag/Drop files from Lazarus Application
« Reply #3 on: October 24, 2018, 08:38:56 am »
Worked flawlessly, many thanks.

I've added the following acknowledgement to the top of the supplied unit

Code: Pascal  [Select]
  1. (* Source: http://forum.lazarus.freepascal.org/index.php/topic,42920.msg299974.html
  2.    Contributed by forum user @ASerge
  3. *)      
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines