views:

184

answers:

4

I have not yet found the best solution for this. I have a non modal dialog that can be opened in unlimited instances by a hotkey in the application. Even the dialog itself can open a new instance. I want those dialogs to always be front of the main application window. I have tried a couple of things.

  • Set FormStyle to fsStayOntop. This works but have the advantage that the dialog will be front of ALL windows even other applications. I only want it to be front of my main window.
  • Set PopupMode to pmAuto. This also works except for the case when one dialog open another dialog. If the first dialog is closed then it automatically close the second one. This is not acceptable.
  • Use the default properties for a form. As soon as the main window is clicked on the opened dialogs is behind the main window.

Any other suggestions :-)

A: 

You can try watching the OnHide event and immediately making the Visible flag to TRUE. This will probably cause flicker though.

gbrandt
This is about the z-order of visible windows.
Andreas Rejbrand
+5  A: 

From TCustomForm.PopupParent Property;

If the PopupMode property is set to pmExplicit and PopupParent is nil, then the Application.MainForm is implicitly used as the PopupParent

.

Sertac Akyuz
Thanks, a quick test confirmed that it seems to work fine. I didn't know that pmExplicit worked that way.
Roland Bengtsson
Thanks for the points @Roland, they've got me a new nice round rep. :)
Sertac Akyuz
+1  A: 

AFAIK Delphi 2007 support MainFormOnTaskbar feature. With

   Application.MainFormOnTaskbar := True;

in project source ANY application form (with default parent window) is shown above main form.


If you are unsure what form is the Main Form, go to Project/Options/Forms and set the correct Main Form. Another probable reason is that you are upgrading a project from a previous Delphi version so the project source does not contain the above line of code - add this line manually.

Serg
Hm, I think I tried that one but I don't remember why I didn't like that. It could be something like taht the first window opened is a login dialog. After that the main window is showned and used as usual. But the information is good to have anyway.
Roland Bengtsson
A: 

I think your first effort, fsstayontop, is the best option. The issue with displaying in front of other applications may be impossible to avoid since you are really using Windows function not something unique to Delphi.

As I recall it is possible to manually set the Z order, but that is tedious to impossible in most apps.

If your dialog is not so big as to hide other applications, it can be moved and users can still access the other apps without first interacting with your dialog. Seems not too bad.

Patrick Moloney