You really need to pass the window handle to the memo control, but then you also need to listen to the WM_DROPFILES message sent to it:
unit Unit5; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellAPI; type TMemo = class(StdCtrls.TMemo) protected procedure WMDropFiles(var Message: TWMDropFiles); message WM_DROPFILES; procedure CreateWnd; override; procedure DestroyWnd; override; end; TForm5 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form5: TForm5; implementation {$R *.dfm} procedure TForm5.FormCreate(Sender: TObject); begin end; { TMemo } procedure TMemo.CreateWnd; begin inherited; DragAcceptFiles(Handle, true); end; procedure TMemo.DestroyWnd; begin DragAcceptFiles(Handle, false); inherited; end; procedure TMemo.WMDropFiles(var Message: TWMDropFiles); var c: integer; fn: array[0..MAX_PATH-1] of char; begin c := DragQueryFile(Message.Drop, $FFFFFFFF, fn, MAX_PATH); if c <> 1 then begin MessageBox(Handle, 'Too many files.', 'Drag and drop error', MB_ICONERROR); Exit; end; if DragQueryFile(Message.Drop, 0, fn, MAX_PATH) = 0 then Exit; Text := fn; end; end.
In the above example, only deleting one file is allowed. The file name will be placed in the recording control. But you can also allow deletion of several objects:
var c: integer; fn: array [0..MAX_PATH-1] from char; i: integer; to begin
c := DragQueryFile(Message.Drop, $FFFFFFFF, fn, MAX_PATH); Clear; for i := 0 to c - 1 do begin if DragQueryFile(Message.Drop, i, fn, MAX_PATH) = 0 then Exit; Lines.Add(fn); end;
source share