I want to be able to drag a image across the form and drop it, like you might do in a solitaire game. I am using this wiki as guidance but not having any luck:
http://wiki.freepascal.org/Drag_and_Drop_sample1. I set the Dragmode on the image and the form to dmAutomatic
2. I set the image OnMouseDown even to start the drag
When I click on the image nothing happens so I must be missing something.
Here is the test code:
unit main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Image1: TImage;
procedure FormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then {check if left mouse button was pressed}
Image1.BeginDrag(true); {starting the drag operation}
end;
procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := true;
end;
end.