Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MessageDlg is hidden behing modal form

Status
Not open for further replies.

Nordlund

Programmer
Jul 17, 2001
458
SE
Hi there everybody.
I have a strange problem... And it sdoesnt pop up every time...

I create an application with 2 forms.
In a button on Form1, I Add Form2.ShowModal.
In Form2 I have a button with ShowMessage.

When I'm running this app and klick the both buttons, I get the Message. Thats Ok.

But the problem will be shown sometimes when I use ALT+TAB to change Windows. When I'm back to the application, the message is hidden behind Form2.

Has anyone delt with this problem?

//Nordlund
 
I don't know if this helps -
but try to execute Application.BringToFront when Form2 is activated (OnActivate).

I have seen something like this happen using other Delphi programs, but they were not mine so I didn't think about what could be the solution for this problem ;-)
 
Hi.
That would help... If I would show a regular form.
But what if it's a form generated by the function MessageDlg and ShowMessage. Theese functions generates their own forms.



//Nordlund
 
I clicked together such an application - two forms which one button each, and

procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.ShowModal;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
MessageDlg('Hey', mtInformation, [mbOK], 0);
end;

Then I execute it until the message box is displayed and change apps with ALT-TAB, but everything stays where it should be.

Can you identify anything that is different when the error occurs?
 
Hi.
This happens very rarely, but it happens.

The Dialog 'Hey' is hidden behind Form2, and it's out of reach for the enduser.

//Nordlund
 
Hi again.
I've read something about this somewhere on the Internet, but it was for a while ago (When Delphi 5 was about to be released). I don't remember if a solution to the problem was mentioned...

But the problem is still around, but it's not often it pops up....

//Nordlund
 
I am struggling with a simialr problem and have not yet found a solution.
 
does this help ??

Message Box on top of "stay on top" forms

The following code causes "stay on top" forms to allow a MessageBox to appear on top. After the message box is closed, the topmost forms are restored so that they continue to float to the top.
~~~~~~~~~~~~~~~~~~~~~~~~~
with Application do
begin
NormalizeTopMosts;
MessageBox('This should be on top.', 'Look', [mbOK]) ;
RestoreTopMosts;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Aaron Taylor
John Mutch Electronics
 
Hi.

Well, I don't think it's goning to work. It's not the actual MessageDlg causing the problem, it's the ALT-TAB command crashing the Topmost structure.

...But thanks for the tip anyway, it's worth a try...

I have experienced the same problem using normal windows shown with "ShowModal", not just MessageDlg and/or ShowMessage

//Nordlund
 
Try:
Code:
  with Application do
  begin
    NormalizeAllTopMosts; 
    MessageDlg('Hey', mtInformation, [mbOK], 0);
    RestoreTopMosts;
  end;
NormalizeAllTopMosts behaves like the NormalizeTopMosts method, except that it also includes the application’s Main Window.

This may be of help to you - apologies if not.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Hi.
I'll try it.
aaronjme wrote the exact same example above...

Thanks guys...

//Nordlund
 
Nordlund said:
aaronjme wrote the exact same example above...

Actually, there IS a subtle difference (as I mentioned after the code sample). Use NormalizeAllTopMosts rather than NormalizeTopMosts as the former includes the application's main window too.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Sorry mate...
I didn't see that... My mistake.



//Nordlund
 
Norlund, what operating system are you using? We've had some strange behavior with forms in XP.

leslie
 
Hi.
I'm also running on Windows XP, but I think many of our customers are running on Win2k.

(I have experienced it on WinXP).

//Nordlund
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top