How to prevent doing 2 modals

I have a nice complex window with 30 containers and classes. Sometimes I need to show the usual error message. Sometimes the code has an unhandled exception and an “error report” window is shown. Somehow I can manage to show both at once and neither window can be clicked. The end result is like this:

The error message is a message dialog:

dim theAlert as new MessageDialog
theAlert.Message = theMessage
theAlert.Explanation = theExplanation

if Button <> "" then theAlert.ActionButton.Caption = Button
call theAlert.ShowModal

if theThread <> nil then theThread.resume

The error report window is shown like this:


I’m not using any threads here. I made the unhandled exception in a code with a timer.

Does anyone have an idea how I might fix this?

We face the same issue (mostly on Windows) so I’ve been thinking about it a lot. The solution I came up with (that I have yet to implement) is:

  • Change all MsgBox calls to use our standard QuickAlertDialog function.
  • Override the ShowModal methods in our Window base class to set a flag, and make sure all our dialogs are using that as a super.
  • Refactor QuickAlertDialog to set that flag when it shows a dialog.
  • Refactor QuickAlertDialog to queue the message and explanation when a dialog is already showing, discard identical requests, and show the next dialog when the current one closes.

I’ve probably missed some edge cases, but that’s the general idea.

1 Like

Actually, when a dialog is showing, QuickAlertDialog should set or reset a Timer to show the next dialog since it might not have been the one to show the current dialog.

1 Like

Thanks for the ideas, Kem. It sounds like I need to refactor some stuff. I have 2 bases classes, one for handling error messages and one for the error reports. I will need to combine those 2. I already have a timer to filter out duplicate error messages.

We simply animate a container control to come down from the top of the front most window (the error caller). It’s a simple row (container control) that has a background color and a label on it. Easy and can be done on most (if not all) window types.

I have something similar, but istead of showing msgboxes or another kind of modal windows, I made a custom alert window. It is not modal but it has a TopMost property, so, this alerts dont block any other modal, like the error report window.

From there, I have a auto close feature with a timer for some cases, stacking to show varios messages at a time, etc

Before BS I’d have tried to do a custom alert window. But BS now has those wonderfully tiny excuses for message dialogs.

Normally, the execution should stop for the error message because the user has to do something. But the exception trumps that because the app is going down anyways. The app knows that there is a message dialog. But can I close those in code?