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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShowMessage issues (chaning window focus) 1

Status
Not open for further replies.

GoldenEye4ever

Programmer
May 26, 2007
20
CA
I'v written a "Windows VLC Forms" app consisting of roughly 10 separate Windows Forms.

I'm having a strange issue with using both the: "ShowMessage(...)" and "MessageDlg(...)" functions.

If I call either function from any Form, other than Form1 (the initial form in the VLC application), Form1 is given focus.

Steps to replicate issue:
- User navigates to Form2 (or any Form other than Form1)
- User clicks the "Save" button
- Form1 is given focus (this is the issue)
- MessageDlg(...) dialog is presented, and is given focus over Form1
- However, Form1 is still visible over Form2
- Once user closes MessageDlg(...) dialog, either by clicking one of the buttons or the "X", Form1 regains focus

My attemp to combat this issue:
- In my code, immediately following each instance of "ShowMessage(...);" and "MessageDlg(...);", I've added "Form2.focus();".
- However, this only restores focus to the correct Form after the dialog is closed.
Form1 is still covering Form2 while either dialog is visible


Please help :)


This weird issue happens both on XP and VISTA.

I initially developed my code in XP, using TurboDelphi.
However, I've re-compiled in VISTA using both "Delphi 2007" and "Delphi 2009 trial" to no avail :(

I'd be open to using custom Dialog boxes if anyone knows of any that work well :)
 
In my code, immediately following each instance of "ShowMessage(...);" and "MessageDlg(...);", I've added "Form2.focus();".

You'd have to add Form2.Focus(); before the message dialog, otherwise it waits for you to click "OK" before the code continues.

Also, how are you showing the other forms?
Formx.Show;
or Formx.ShowModal;?
Or any other way?
 
I'll try "Form2.Focus();" when I get home tonight.

I'm calling all the forms with "FormName.ShowModal();".

Also, I've noticed that this issue is not occurring in VISTA, sorry about that, it only happends in XP :(
 
I created a test app in delphi 6 on xp,
form1 has a button form2.showmodal
form 2 has a button showmessage('hello');
I had no problem

Aaron
 
I'm not saying that this makes any sense :(

I've used ShowMessage(...) and MessageDlg(...) before many times with no issues.
But this time it's acting strange.

I initially developed the app in XP using Turbo Delphi (Delphi 2006), then moved it to my VISTA install using Delphi 2007.

It only seems to happen on an XP pc.

-------------------

Also, I tried adding the "FormName.setFocus()" on the line right before the ShowMessage(...) dialog, and it didn't help.

When I ran the exe on XP, it still did the screwy loss of focus.
 
Same as Aaron here. I did a test app where I had one button on Form1 that showed Form2, and then a button on Form2 that popped up a Dialog Box. Focus always returned to form2.
Delphi 3 and Turbo Delphi 2006 on Windows XP.

There must be something strange that is happening in your code.

Measurement is not management.
 
Thanks a lot for your efforts, I appreciate the help.

I really don't wanna re-write everything in Delphi 2007 from scratch as my app is roughly 12,000 - 16,000 lines of code now :(
I sorta lost count :S

Well, I'm away from my PC for the weekend.

I guess when I get home on Monday, I'll try making a new app in TurboDelphi, under XP.
Very simple, just like you guys described your tests.

Then I'll see if it gives my any grief.
Then I'll re-compile that same source in Delphi 2007 under VISTA and try running that exe on XP.

If I can't re-produce my error that way, then I'll be really annoyed.


I'll keep you all notified :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top