Drag and drop an image from the browser onto the application form.
How to catch this event?
Event OnDropFiles and property AllowDropFiles set and not working from this case.
Need a cross-platform solution (windows, linux)
Seem to work as expected for me.
However there is a big if. If the picture you want to drag actually contains a link to a webpage then the link (to that webpage) will be copied instead of the link to the actual image. And with that I also told you the other catch and that is that you only receive the link to the image (at least with Firefox on Linux as I only tested that). You would still have to actually download the image.
Memo1
files dropped
https://www.lazarus-ide.org/
files dropped
https://forum.lazarus.freepascal.org/index.php?action=profile;u=39078
files dropped
https://duckduckgo.com/?q=sample%20images&iax=images&ia=images&iai=https://cdn.photographylife.com/wp-content/uploads/2014/09/Nikon-D750-Image-Samples-2.jpg&t=ffab
The first "image" was the picture you see at the left top when you read these forums (links to a website, not the actual image).
The second "image" was the picture of user Handoko (links to a user profile webpage, not the actual image).
The last picture is a search for "sample images" at duck duck and I dragged and dropped the first image.
So, dragging and dropping images from a browser to a lazarus application might perhaps not be the most intuitive thing to do.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Self.AllowDropFiles:= true;
end;
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
var
Filename: string;
begin
Memo1.Append('files dropped');
for Filename in Filenames
do Memo1.Append(filename);
end;
end.
Also note that, depending on the platform, it is not possible to receive messages from non-elevated application to an elevated application. This comes into play for users that have installed and run Lazarus as an elevated application (while the browser or other application you drag the image from is not running elevated).