Ian Branch 127 Posted January 18, 2023 Hi Team, I have a Timer routine that runs every minute. The routine detects if there is an AlertMessage.txt file present and if there is, opens it, populates then executes the modal dialog. It does this every minute. If the User doesn't acknowledge the first dialog another will be popped up on top. And so on.. Is there some way to detect if the original dialog is still open so subsequent executions don't occur? Regards & TIA, Ian Share this post Link to post
SwiftExpat 65 Posted January 18, 2023 This should get you started, I match mine by classtype. for i := 0 to Screen.FormCount - 1 do // itterate the screens if Screen.Forms[i].ClassType = TSERTTKMarshalForm then begin Screen.Forms[i].Show; if Screen.Forms[i].WindowState = TWindowState.wsMinimized then Screen.Forms[i].WindowState := TWindowState.wsNormal; exit; end; Share this post Link to post
Anders Melander 1784 Posted January 18, 2023 I'm not sure I understand your description, but you might: Check Application.ModalLevel to determine if a (Delphi) modal dialog is active. Check Screen.ActiveForm to determine exactly which form is currently active. or simply avoid the problem altogether by not executing the timer code while a modal dialog is active: procedure TMyForm.TimerAlertMessageTimer(Sender: TObject); begin TTimer(Sender).Enabled := False; try var FormAlertMessage := TFormAlertMessage.Create(Self); try FormAlertMessage.ShowModal; finally FormAlertMessage.Free; end; finally TTimer(Sender).Enabled := True; end; end; or procedure TMyForm.TimerAlertMessageTimer(Sender: TObject); begin if (Application.ModalLevel > 0) then exit; // Modal dialog is active; Punt! var FormAlertMessage := TFormAlertMessage.Create(Self); try FormAlertMessage.ShowModal; finally FormAlertMessage.Free; end; end; 1 Share this post Link to post
Ian Branch 127 Posted January 18, 2023 Thanks Guys for your suggestions. Doh!! So simple! Just disable/enable the timer... I'm embarrassed. 🙂 Regards & Tks Again, Ian Share this post Link to post
programmerdelphi2k 237 Posted January 19, 2023 (edited) if using "if YourForm.SHOWING then = "opened" in your screen" not? Edited January 19, 2023 by programmerdelphi2k Share this post Link to post
uligerhardt 18 Posted January 19, 2023 Depending on your needs a non-modal solution might be better - something like Windows' toast notifications. I use DevExpress' dxAlertWindow for that. Share this post Link to post