Discussion:
Big Problem in Delphi with Modal Forms (Please Help)
(too old to reply)
Dave Nottage (TeamB)
2003-07-23 06:38:04 UTC
Permalink
I have some problem with modal form.
I have some main form "Form1" and some other form "Form2", when I
call from Form1 the method Form2.ShowModal; it show the modal form,
when I'm try to click on Form1 it can't get focus (the Form2 is
modal), BUT WHEN I PRESS ALT+TAB IT SELECTS THE FORM1 AND HIDS FORM2,
SO I CAN'T MAKE ANY ACTION WITH MOUSE, THE FORM2 IS MODAL AND IT'S
HIDDEN!!!
I think it's a big bug of Borland, the Delphi IDE has this error too
(I use WIN XP SP1).
Try to open Help\About form of Delphi and then press Alt+Tab, the
main form of Delphi will be selected!!!
Doesn't happen for me in either case, using Win XP SP1.
--
Dave Nottage (TeamB)
Tomski
2003-07-23 07:07:00 UTC
Permalink
Hello!
I have some main form "Form1" and some other form "Form2", when I call
from
Form1 the method Form2.ShowModal; it show the modal form, when I'm try to
click on Form1 it can't get focus (the Form2 is modal), BUT WHEN I PRESS
ALT+TAB IT SELECTS THE FORM1 AND HIDS FORM2, SO I CAN'T MAKE ANY ACTION
WITH
MOUSE, THE FORM2 IS MODAL AND IT'S HIDDEN!!!
I think it's a big bug of Borland, the Delphi IDE has this error too (I
use
WIN XP SP1).
I don't know if this is Borland's or Windows' bug. But I also noticed such
behaviour. The only method of returning to modal form I found is to switch
to other application and minimize it. Then the modal form will show up.
Regards,
Tomski
Illya Kysil
2003-07-23 07:13:21 UTC
Permalink
I have some problem with modal form.
I have some main form "Form1" and some other form "Form2", when I call from
Form1 the method Form2.ShowModal; it show the modal form, when I'm try to
click on Form1 it can't get focus (the Form2 is modal), BUT WHEN I PRESS
ALT+TAB IT SELECTS THE FORM1 AND HIDS FORM2, SO I CAN'T MAKE ANY ACTION WITH
MOUSE, THE FORM2 IS MODAL AND IT'S HIDDEN!!!
I think it's a big bug of Borland, the Delphi IDE has this error too (I use
WIN XP SP1).
Try to open Help\About form of Delphi and then press Alt+Tab, the main form
of Delphi will be selected!!!
But the About form must be modal form and it's ok when I try to select back
form with mouse click, but when I press Alt+Tab the bach form gets focus!
How can I solve this problem?
I've noticed exactly such behaviour in several applications not only Delphi based.
IMHO this is a bug in Windows.
--
Regards
Illya Kysil, software developer
Delphi/C/C++/C#/Java/Forth/Assembler
If it is NOT SOURCE, it is NOT SOFTWARE. (C) NASA
Barry Morris
2003-07-23 10:30:58 UTC
Permalink
This has been a very big problem for my product for years, on Windows NT,
2000 & XP that is. Incidentally I have been looking at MS Server 2003 and
Microsoft hide some of their own modal forms behind parent forms.

In the end I wrote an ApplicationEvents OnActivate event that iterates
through all the visible forms, if there are two and one is the Mainform I
assume the other is modal so call
SetForegroundWindow(Screen.Forms[n].Handle);

If there are more than two visible forms I hard code the order and set the
correct one to the foreground. If there are more than two visible forms and
they are not in my list the first visible form that isn't the main form
seems to be the correct form to bring to the foreground:

for n := 0 to Screen.Formcount -1 do
if Screen.Forms[n].Visible and (Screen.Forms[n].Name <>
'fAquariusBackup') then
begin
{$IFNDEF Live}
LogMessage('WIN','Guess: > 2 Brought to front:
'+Screen.Forms[n].Name);
{$ENDIF}
SetForegroundWindow(Screen.Forms[n].Handle);
break
end;

I log a message during testing so that the 'Guesses' can be hard coded.

This is a pain and is contrary to what a modal form has been defind, as far
as I am concerned it is a bug in Windows NT, 2000, XP & Server 2003 that we
must code around or the users of your program are going to think is has
hung, and most users re-boot rather than use task manager, whereas clicking
the application on the task bar twice usually brings the correct window to
the foreground.

I wish Borland could keep track of the Show Modal / 'Form not showing modal'
(and dialogs) etc to re-stack the visible forms properly.

Other interesting things can happen on Windows XP:

If your program is busy working on data the form may end up 'Not Responding'
unless regular calls to Application.ProcessMessages are made.

Occasionally parent forms behind modal forms can be moved with the mouse,
why???

The suggestions I have given may not work for non Delphi forms, e.g.
OpenDialog etc.

I hope this helps.

Barry
Finn Tolderlund
2003-07-23 10:51:26 UTC
Permalink
It's a new "feature" in XP called windowsghosting.
This has been disgussed in length with why it happens ans what to do about
it.
Searh http://groups.google.com/ for disableprocesswindowsghosting and you
will find a lot of information about it.
--
Finn Tolderlund
Post by Barry Morris
If your program is busy working on data the form may end up 'Not Responding'
unless regular calls to Application.ProcessMessages are made.
Occasionally parent forms behind modal forms can be moved with the mouse,
why???
David Dvali
2003-07-23 12:31:59 UTC
Permalink
Can you send me a DEMO please?
Post by Barry Morris
This has been a very big problem for my product for years, on Windows NT,
2000 & XP that is. Incidentally I have been looking at MS Server 2003 and
Microsoft hide some of their own modal forms behind parent forms.
In the end I wrote an ApplicationEvents OnActivate event that iterates
through all the visible forms, if there are two and one is the Mainform I
assume the other is modal so call
SetForegroundWindow(Screen.Forms[n].Handle);
If there are more than two visible forms I hard code the order and set the
correct one to the foreground. If there are more than two visible forms and
they are not in my list the first visible form that isn't the main form
for n := 0 to Screen.Formcount -1 do
if Screen.Forms[n].Visible and (Screen.Forms[n].Name <>
'fAquariusBackup') then
begin
{$IFNDEF Live}
'+Screen.Forms[n].Name);
{$ENDIF}
SetForegroundWindow(Screen.Forms[n].Handle);
break
end;
I log a message during testing so that the 'Guesses' can be hard coded.
This is a pain and is contrary to what a modal form has been defind, as far
as I am concerned it is a bug in Windows NT, 2000, XP & Server 2003 that we
must code around or the users of your program are going to think is has
hung, and most users re-boot rather than use task manager, whereas clicking
the application on the task bar twice usually brings the correct window to
the foreground.
I wish Borland could keep track of the Show Modal / 'Form not showing modal'
(and dialogs) etc to re-stack the visible forms properly.
If your program is busy working on data the form may end up 'Not Responding'
unless regular calls to Application.ProcessMessages are made.
Occasionally parent forms behind modal forms can be moved with the mouse,
why???
The suggestions I have given may not work for non Delphi forms, e.g.
OpenDialog etc.
I hope this helps.
Barry
Loading...