- Create a new project and a new form.
- Add a memo and a label to the form.
- Enable the AllowDropFiles property of the form.
- Add the following code to the OnDropFiles event of the form:
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of String
);
var
i : Integer;
begin
label1.Caption := '';
for i:=low(FileNames) to high(FileNames) do
label1.Caption := label1.Caption + LineEnding + FileNames[i]
end;
Then run the application and drag-drop some files from Nautilus (file manager) to the application.
Label1 should display their names. If you drop the files to
Memo1 instead of an empty area on the form, a string containing the file names will be added to
Memo1 contents.
For more strange things do this:
Select some text from
Memo1 and try to drag-drop it somewhere
within Memo1 (something that you cannot do if the application were run in Windows). The contents will be moved, but some garbage will be displayed in
Label1 (see attached screenshot), because the
OnDropFiles event of the form is fired!