Link to home
Start Free TrialLog in
Avatar of rfwoolf
rfwoolfFlag for South Africa

asked on

Horrible Modal Form Bug!

Try this in a new application...

Form1:
  -> Add a Tbutton
  -> Double-click the button and type "Form2.Showmodal;"
Form2
  -> Add a Tbutton
  -> Double-click the button and type "Form3.Show;"
Form3
  -> Add a Tbutton
  -> Double-click the button and type "Form1.show;

Now run the application, and move Forms 2 and 3 BEHIND Form 1.
Now click all the buttons.

The problem is that now your application is locked... Form1 remains in the front but is not active and you can't access Forms 2 and 3 behind it.
One workaround is to Alt-Tab out of the application and Alt-Tab back in... but you cannot POSSIBLY expect users to know about this.
How do you fix this horrific problem?

Notes: Using Delphi BDS 2006 and running XP with Service Pack 2
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

if you are creating form2 and form 3 modally, then i would expect you to close them before returning to form1....
If your intention is to leave them visible, then these should not really be modal forms...
You can achieve a similar effect by using a compbination of 1 or more of
form.show, form.enabled
form.bringtofront
and even
formstyle := fsStayOnTop (reverting to normal when not required to be on top)
The "cyclic" nature of your forms implies that the Modal style is not suitable for your needs.

If your intention is to go back to form1 nad then start the cycle again, then you should Form.Hide the other forms before bringing up form1 again...
Avatar of rfwoolf

ASKER

"if you are creating form2 and form 3 modally,"
...nope, only Form2 is modal. The idea here is that
  Form 1 calls Form2.Showmodal and
  Form 2 calls Form3.Show and
  Form 3 calls Form1.Show
..and this could block the modal form and freeze the application.
In terms of design you would have to make sure that Form 2 is 'larger' than Form 1 and 3 so that it can't get stuck behind them - and that's rather pathetic and in some cases not possible.
Bottom line is that in theory you cannot have a modal form calling another form which calls another form.

If a form is shown modally, then even if it calls Form.show and shows other forms who have FormStyle fsNormal those other forms should *NOT* appear in front of the modal form. The Modal form must be the top-most form in the application.
imho a modal form should not be creating other forms unless they are also created as modal
this is best way on how to confuse windows :-)))

this flow isn't practicable

meikl ;-)
I had the same problem.
Had to program a logout of the database, after some idle time.
The user had to be given a login dialog after the idle time passed.
And off course the login dialog was behind the main form.

Instead of providing the book "Dummy windows for intelligent users"
I had to provide the solution programmatically
...

This off course was only for 1 window
procedure TfrmMain.TimerLoginDialogTimer(Sender: TObject);
var
  I: Integer;
  aLoginDialog: TLoginDialog;
begin
  for I := 0 to Screen.FormCount-1 do
    if Screen.Forms[I] is TLoginDialog then
    begin
      aLoginDialog := TLoginDialog(Screen.Forms[I]);
      if aLoginDialog.Visible and Application.Active then
        aLoginDialog.BringToFront;
    end;
end;

Open in new window

I forgot to mention i start a timer after logout

and stop it after login
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rfwoolf

ASKER

Geert that's a great solution, however I'd need to be more encouraged before using it.
The problem is that when I do my tests everything seems fine, but I went to install on a client's network and there XP was, er, different. If they Alt+Tabbed for example I could see that there was more than one icon in the Alt-Tab thingy for my application - such as one icon for the application and one for a popup message.
Anyway long story short, things seem different on their network and that's where the problem appears. Compounding the problem is that their PCs are a bit slow, and the network is a bit slow - so it COULD BE GHOSTING as I've explained on a different question (where XP thinks the application has frozen and changes the order of the forms). In any case, the scenario I've presented in this question occurs WITHOUT ghosting and even in the IDE where ghosting is disabled.

So I can try your solution, but honestly I thought by now there would be some documented cases of this happening with an explanation and rataionale. I'm disappointed at the lack of knowledge and documentation on it.
For what it's worth, THANKS for your input because nobody else seems to know what the hell I'm talking about :)
are you running anything slow in the mainthread like calculations or database operations ?
if you are, maybe move that in a thread, that way the application (mainthread) keeps responding ...