You can use the flag in your main form, which your other forms would check before asking the user whether to continue or not. Something like that:
block1
type TForm1 = class(TForm) .. public UnconditinalClose: Boolean; end; .. procedure TForm1.Timer1Timer(Sender: TObject); begin UnconditinalClose := True; end;
unit 2:
implementation uses unit1; procedure TForm2.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose := unit1.Form1.UnconditinalClose; if not CanClose then // ask the user if he/she sure he/she wants to close end;
Another solution might be to remove OnCloseQuery
event handlers of other forms. This would be practical only if these other forms were released (released) upon closing and not hidden (edited to reflect Rob's comment):
procedure TForm1.Timer1Timer(Sender: TObject); var i: Integer; SaveHandler: TCloseQueryEvent; begin for i := 0 to Screen.Formcount - 1 do if Screen.Forms[i] <> Self then begin SaveHandler := Screen.Forms[i].OnCloseQuery; Screen.Forms[i].OnCloseQuery := nil; Screen.Forms[i].Close; Screen.Forms[i].OnCloseQuery := SaveHandler; end; end;
source share