Detect MessageDlg box lazarus / 31-LCL ---------------------------------------------------------------------- johnkdevnull · 2014-03-05 21:58 I have my application set to minimise on application.onDeactivate except when application.modallevel is > 0.  However this test does NOT detect messagedlg boxes.  Nor does it detect application.messagebox.  Should these dialogs not increment the modallevel count? Any suggestions on how to detect if one is open? This is on Lazarus 1.3 (SVN) and Fedora 20 using GTK2. ---------------------------------------------------------------------- kpeters58 · 2014-03-08 21:35 I am not aware of some built-in detection. But since you are in charge of all the message boxes you pop up, wouldn't a simple wrapper with a state variable do the trick? Code: [Select]var    DialogVisible: Boolean; procedure ShowMyDialog; begin    DiaglogVisible := True;    MessageDlg('bla', 'bla', mtInformation, [mbOK], 0);    DiaglogVisible := False end; ---------------------------------------------------------------------- jwdietrich · 2014-03-08 21:50 Wouldn't an integer variable counting the open modal dialog boxes be better? This would ensure correct handling if dialog box A opens dialog box B (and possibly so on). Code: [Select]var    modallevel: integer; procedure ShowMyDialog; begin    inc(modallevel);    MessageDlg('bla', 'bla', mtInformation, [mbOK], 0);    if modallevel > 0 then      dec(modallevel); end; ... modallevel := 0; ---------------------------------------------------------------------- eny · 2014-03-09 08:43 Quote from: jwdietrich on March 08, 2014, 10:50:54 pmCode: [Select]   if modallevel > 0 then      dec(modallevel); end; The test for > 0 just after the increse is rather pointless. Why not test the first incresae also for >= 0? If you do it to prevent errors, then better add an exception handler so you get notified if there is a logic error somewhere. ---------------------------------------------------------------------- jwdietrich · 2014-03-09 15:51 Quote from: eny on March 09, 2014, 09:43:55 amQuote from: jwdietrich on March 08, 2014, 10:50:54 pmCode: [Select]   if modallevel > 0 then      dec(modallevel); end; The test for > 0 just after the increse is rather pointless. Why not test the first incresae also for >= 0? If you do it to prevent errors, then better add an exception handler so you get notified if there is a logic error somewhere. The test should prevent modallevel from getting negative values, but you are right, an exception handler would be the better solution. ---------------------------------------------------------------------- zeljko · 2014-03-15 20:58 Quote from: johnkdevnull on March 05, 2014, 10:58:57 pmI have my application set to minimise on application.onDeactivate except when application.modallevel is > 0.  However this test does NOT detect messagedlg boxes.  Nor does it detect application.messagebox.  Should these dialogs not increment the modallevel count? Any suggestions on how to detect if one is open? This is on Lazarus 1.3 (SVN) and Fedora 20 using GTK2. What's Delphi behaviour in this case. Does it count dialogs as other modal forms ? ---------------------------------------------------------------------- johnkdevnull · 2014-03-21 19:00 Looking at my old copy of Delphi 7, it doesn't have an application.modallevel property.  Later versions might I suppose.