Delphi-Quellcode:
type
TExitFormHelper = class helper for TForm
private type
TProtectedControl = class(TWinControl);
public
procedure CheckOnExit(WithOnEnter: Boolean=False);
end;
procedure TExitFormHelper.CheckOnExit(WithOnEnter: Boolean);
begin
if not Assigned(Self.ActiveControl) then
Exit;
TProtectedControl(ActiveControl).DoExit;
if WithOnEnter then
TProtectedControl(ActiveControl).DoEnter;
end;
Und dann halt im OnCloseQuery/OnClose/OnDestroy und eben in den ClickEvents von Menüs/SpeedButtons das CheckOnExit aufrufen.