Here is my simple code which compiles well, but raise Access Violation. It enters MD procedure and debugger displays some X and Y value, but after exiting procedure AV happens. Hope someone can help.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Controls, Forms, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure MD(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
form1.caption:= inttostr(x)+ ' '+ inttostr(y);
end;
procedure TForm1.FormCreate(Sender: TObject);
function MakeMethod(data, code: pointer): TMethod;
begin
result.Data:= data;
result.Code:= code;
end;
begin
panel1.OnMouseDown:= TMouseEvent(MakeMethod(nil, @MD));
end;
end.
Thanks
MDnever referencesdatapointer, the actual reason of failure is parameter mismatch.MDa method ofTForm1you could try the technique I described here: stackoverflow.com/questions/11083336/….