I'm trying to figure out how to use drag and drop files from the windows explorer to my application.
I found several info and examples but none of them seem to work.
So I started from scratch by creating an empty form.
According to a post this should work:
and therefore
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String);
var
i: Integer;
begin
for i := Low(FileNames) to High(FileNames) do
DoSomeThingWithFile(FileNames[i]);
// ShowMessage('Ok');
end;
Nothing is happening.
This is a minimal example but I have tried several others with no success.
Another example;
function CreateFileDropSite(const AControl: TControl;
const ADropFilesEvent: TDropFilesEvent): TForm;
begin
Result := TForm.Create(AControl);
Result.AllowDropFiles := True;
Result.BorderStyle := bsNone;
Result.BoundsRect := AControl.BoundsRect;
Result.Align := AControl.Align;
Result.Parent := AControl.Parent;
Result.OnDropFiles := ADropFilesEvent;
AControl.Parent := Result;
AControl.Align := alClient;
Result.Visible := True;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
LD1 := CreateFileDropSite(shelllistview3, @FormDropFiles);
end;
procedure TMainForm.FormDropFiles(Sender: TObject;
const FileNames: array of String);
begin
if Sender = LD1 then
begin
ShowMessage('Ok');
end;
end;
or:
procedure TForm1.FormCreate(Sender: TObject);
begin
AllowDropFiles:= True;
DragAcceptFiles(Handle, False);
DragAcceptFiles(memo1.Handle, True);
end;
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String);
begin
if Length(FileNames) > 0 then
memo1.lines.add := FileNames[0];
end;
I have no problem with drag and drop inside my application but from the outside I can't get over it.
Is there something I'm missing?
(Lazarus ver. 2.0.12)