3

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 :-)

Roland Bengtsson
  • 5,058
  • 9
  • 58
  • 99
  • 1
    I have probably misunderstood you, because as far as I can tell, the behaviour that you desire is the default behaviour. See http://privat.rejbrand.se/zorder.exe – Andreas Rejbrand Aug 23 '10 at 16:14
  • Just made a quick test for that and you are right. Cannot say why my application don't behave like that. It could be that there is both a Splash and a login dialog before the main window. But Sertacs solution worked for me. – Roland Bengtsson Aug 23 '10 at 16:39

4 Answers4

7

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
  • 54,131
  • 4
  • 102
  • 169
2

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.

kludg
  • 27,213
  • 5
  • 67
  • 118
  • 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 Aug 23 '10 at 16:31
0

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.

-1

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

Gregor Brandt
  • 7,659
  • 38
  • 59