[Lazarus] Modifying Form Event

Steve Gatenby steveg at nevets.com.au
Thu Mar 13 13:15:44 CET 2014


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




More information about the Lazarus mailing list