Solved

Disappearing messageDlgs

Posted on 2003-12-04
8
1,027 Views
Last Modified: 2012-08-13
Hi all,

I've got the following problem :
I've created an application, which uses a pagecontrol to show different parts of functionality of the program. For the setup part of the program, I've chosen to add a form, which "hovers" above the mainform. Because the setupform would disappear if I clicked on the mainform, I've made the setupform.FormStyle fsStayOnTop.

All was well, until I got the bright idea to notify the user if a change had been made...To do the notification, I make use of a MessageDlg. If the user clicks on the button, all is well of course. But when the user clicks somewhere else, the messagedlg disappears, and can only be found by minimizing the application!

I've found one solution myself, but that didn't really help : Using NormalizeTopMost and RestoreTopMost. This does indeed make the setupforms formstyle fsNormal, and the MessageDlg always appears. But now both disappear when I click on the mainform.

The strange thing is, the MessageDlg's I call from the mainform do not have this problem!

Any help would be appreciated!

Binsky
0
Comment
Question by:Binsky
  • 3
  • 3
  • 2
8 Comments
 

Expert Comment

by:hatchy
ID: 9874237
The best thing you can do is not use setupform.FormStyle fsStayOnTop.Instead do

setupform.ShowModal;

when you show the form .. that way the form will stay on top of the others and you wont be allowed to 'play' with the other forms while its open

Now twhen you do a messagedlg the form shouldnt 'overlap' the dialogue but should stay on top of it

good luck :)

--HaTcHeT
0
 
LVL 1

Author Comment

by:Binsky
ID: 9875015
Alright,

I'll checkit out, it seems like a very very good tip to me! I was getting pretty annoyed with the stayontop business...My last project had a lot of checking for stayontop and visibility, I was planning on not having to repeat that in this project...

But it will be a while until I check it, I'm going home from work now, and won't be back till tuesday! (So it'll take a few days for the points, if this works for me, which I'm sure it will..)

Thanks a lot,

Binsky
0
 
LVL 17

Accepted Solution

by:
geobul earned 125 total points
ID: 9875162
Hi,

Try windows.MessageBox function instead:

procedure TForm2.Button1Click(Sender: TObject);
begin
  if windows.MessageBox(Handle, PChar('the text'), PChar('the caption'), MB_OKCANCEL or MB_ICONQUESTION or MB_APPLMODAL or MB_TOPMOST) = IDOK then begin
    // do something
  end;
end;

Regards, Geo
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:Binsky
ID: 9902547
Okay,

I've tried the showmodal, but that is a bit too agressive for my taste...The form doesn't need to "take control" of the application, so that is not a good solution to my problem(sorry)

The messagebox solution also didn't work at first, but after some tweaking I got it to work.

I've solved it so far, using a bit of my own, and a bit of Geo's solution... :

      with Application do
      begin
         NormalizeTopMosts;
         MessageBox('This should be on top.', 'Look', mrOK);
         RestoreTopMosts;
      end;

Geo (or anyone), how do I create a MessageBox which contains only an Ok button? Using the MBOk constant doesn't appear to work for me...Do I need to include something special in my "uses" part of the unit? (I couldn't find which unit I should include in the helpfile).

Binsky


0
 
LVL 17

Expert Comment

by:geobul
ID: 9908371
Hi,

uses Windows; // I hope you already have this in your unit

MessageBox('This should be on top.', 'Look', MB_OK);

Regards, Geo
0
 

Expert Comment

by:hatchy
ID: 9908412
or use

messagedlg( 'hello world', mtinformation, [mbok], 0);

--HaTcHeT
0
 
LVL 1

Author Comment

by:Binsky
ID: 9910579
Hello again,

Thanks Geo, that worked perfectly! Once I included Windows in my uses clause, all worked fine (I didn't have that yet...)

Sorry Hatchy, I know your last post is right, that it does deliver a messagebox with only an Ok button, but the messagedlg function was not the right "component" to solve this problem. But thanks for your time!

So the points are for Geo...

Binsky
0
 
LVL 17

Expert Comment

by:geobul
ID: 9910785
Thanks :-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question