Hoping somebody may be able to explain why the following doesn't stop the Form closing.
Button1 sets the method pointer correctly (I believe), as when closing the form the showmessage occurs as expected (and shows the correct form name).
But the form closes anyway.
procedure MyFormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
ShowMessage('MyCloseQuery:'+TControl(Sender).Name);
CanClose := FALSE;
end;
procedure TformMain.Button1Click(Sender: TObject);
var
OnCloseQueryMethod :TCloseQueryEvent;
begin
TMethod(OnCloseQueryMethod).Code := @MyFormCloseQuery;
TMethod(OnCloseQueryMethod).Data := formMain;
TForm(formMain).OnCloseQuery := OnCloseQueryMethod;
end;Thanks - SteveG
