I want to create windows GUI application using Lazarus that able to drag file from explorer to the TEdit widget and show the file path.
I had read and tried some delphi tutorials, it said that you need to handle the WM_DROPFILES message, but I still can't get it works. So I'm thinking if I should try the simple way first by making application that able to drag file to TForm instead.
So I followed this example, but it doesn't work too.
Here is the full code:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Windows, Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs,
ShellAPI;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
protected
procedure WMDropFiles(var Msg: TMessage); message WM_DROPFILES;
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
DragAcceptFiles(self.Handle, True);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DragAcceptFiles(self.Handle, False);
end;
procedure TForm1.WMDropFiles(var Msg: TMessage);
begin
ShowMessage('hello'); // never gets called
end;
end.
The TForm1.FormCreate
and TForm1.FormDestroy
are working fine but the TForm1.WMDropFiles
method never gets called.
Anyone know the solution? Could be the Lazarus/Free-Pascal windows library behavior differs from Delphi's ?
FYI, I'm using lazarus-1.6.0-fpc-3.0.0-win32 on Windows 7 64 bit.