Hi, i have a problem with the stackframe of the OnMouseDown event of a TImage created at runtime. Note the Timage.OnMouseDown assignment via TMethod.
Upon MouseDown, MouseDownEvent is called with the wrong stackframe. It appears to be off by sizeof(TMouseButton). Is my definition of TMouseEvent incorrect? Regards.
Also, is there a recommended practice to preclude such a declaration mismatch?
Details: Ubuntu 20.04, FPC version 3.2.0 [2020/07/07] for x86_64, Lazarus: 2.0.12
procedure MouseDownEvent(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,Y: Integer);
begin
if not (Sender is TImage) then exit;
Form1.ListBox1.Items.AddText(format('[x,y]: [%d,%d]',[x,y])); // note incorrect [x,y] reporting
end;
procedure TForm1.FormCreate(Sender: TObject);
var
e: TMethod;
begin
img:=TImage.create(Form1);
img.Parent:=Form1;
img.left:=32;
img.top:=32;
img.width:=400;
img.height:=400;
img.Canvas.Brush.Color := clgreen;
img.Canvas.Brush.style := bsSolid;
img.canvas.FillRect(0,0,400,400);
e.Data:=img;
e.Code:=@MouseDownEvent;
img.OnMouseDown:=TMouseEvent(e);
end;