Hi, I've got a problem with the sender object. I want to store the sender as a reference. If I try this with the OnClick event it works, but if I try it with for example the OnMouseDown or OnResize event it doesnt work. For some reason this is handled differently, maybe in the OnMouseDown the Sender object is a copy of the original sender and is freed after the event is done?
Reproduce:
Click on button1 > Click on Button3 > Message is shown with "TButton"
Click on button2 > Click on Button3 > Exception is shown
var
ObjectTest : ^TObject;
procedure TForm1.Button1Click(Sender: TObject);
begin
ObjectTest := @Sender; // Works
end;
procedure TForm1.Button2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ObjectTest := @Sender; // Does not work
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
// when Button1Click it returns "TButton"
// when Button2MouseDown it returns an exception
ShowMessage(ObjectTest^.ClassName);
end;