unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ImageDropTarget;

type

  { TForm1 }

  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ImageDropTargetDrop(Sender: TObject; const KeyState: DWORD;
    const Point: TPoint; const DST: TDropSourceType; const Stream: TStream;
    const FileName: UTF8String; const SR: TSniffResult; var Effect: DWORD);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

uses
  ActiveX;

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
var
  IDT: TImageDropTarget;
begin
  IDT := TImageDropTarget.Create();
  IDT.OnDrop := @ImageDropTargetDrop;
  RegisterDragDrop(Handle, IDT);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  RevokeDragDrop(Handle);
end;

procedure TForm1.ImageDropTargetDrop(Sender: TObject; const KeyState: DWORD;
    const Point: TPoint; const DST: TDropSourceType; const Stream: TStream;
    const FileName: UTF8String; const SR: TSniffResult; var Effect: DWORD);
var
  FS: TFileStream;
begin
  FS := TFileStream.Create(ansistring(FileName), fmCreate);
  try
    FS.CopyFrom(stream, 0);
    Memo1.Lines.Add(fs.FileName);
  finally
    FS.Free;
  end;
end;

end.

