Drag and Drop filesEdit

First, make sure to add ShellAPI to your uses clause, then use the DragAcceptFiles function in the OnCreate event for the form that will accept them.   This will tell Windows to send WM_DROPFILES messages to the application that is registered to accept dropped files, for example:

procedure TForm1.FormCreate(Sender: TObject); 
  DragAcceptFiles(Handle, True); 

Then create a procedure that process the WM_DROPFILES message

procedure DropFiles(var msg: TMessage ); message WM_DROPFILES;

Example implementation:

procedure TForm1.DropFiles(var msg: TMessage ); 
  i, count  : integer; 
  dropFileName : array [0..511] of Char; 
  MAXFILENAME: integer; 
  MAXFILENAME := 511; 
  // we check the query for amount of files received 
  count := DragQueryFile(msg.WParam, $FFFFFFFF, dropFileName, MAXFILENAME); 
  // we process them all 
  for i := 0 to count - 1 do 
    DragQueryFile(msg.WParam, i, dropFileName, MAXFILENAME); 
    // dropFileName now has the current filename of dropped object. 
    // ** 
    // do something :D 
    // ** 
  // release memory used 

See alsoEdit

Code Snippets
DatabasesFiles and I/OForms/WindowsGraphicsNetworkingMath and AlgorithmsMiscellaneousMultimediaSystemVCL

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.