Set the MainForm
as the PopupParent
for the progress form so that the MainForm
can never appear on top of the progress form. Then simply set MainForm.Enabled := False
while the progress form is open and set MainForm.Enabled := True
when the progress form is closed.
procedure TMainForm.ShowProgressForm;
begin
with TProgressForm.Create(nil) do
begin
PopupParent := Self;
OnClose := ProgressFormClose;
Show;
end;
Enabled := False;
end;
procedure TMainForm.ProgressFormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
Enabled := True;
end;
This simulates howShowModal()
behaves to the user (the MainForm
is not user-interactive while the progress form is open), but without blocking the code.