2

I just installed the new Delphi Sydney 2 (10.4.2) and I have found something weird:

  • Create a new vcl app.
  • Add a new form.
  • Set the second form Visible to True (so we can see it). Don't change any other project settings/form properties.
  • Run the app.

The second form will always be on top of the main form.
Setting the FormStyle to fsNormal at run time will not fix the behavior.

Can anyone confirm this behavior?

Gabriel
  • 20,797
  • 27
  • 159
  • 293
  • 4
    Yes, this is the default behaviour. I'd say it is well known. Also: if this was indeed a bug, it wouldn't be a *compiler* bug. It would be a bug in the RTL. Related: https://stackoverflow.com/questions/4241308/how-to-allow-delphi-secondary-forms-behind-the-main-form – Andreas Rejbrand Mar 20 '21 at 10:58
  • @AndreasRejbrand - Looks like I haven't started a new project from IDE, in years. Thanks – Gabriel Mar 20 '21 at 11:41

1 Answers1

1

Solved. I looked back in my existing projects (DPR). They all have Application.MainFormOnTaskbar set to false (totally forgot about it). This is because I always start from a template. Looks like the template predates the Vista era :)

Today I started for the first time an app that was not a copy of that template. This explains why this default behavior is new to me :)

Anyway, I don't want "modal" forms all over in my app. So, I will stick with MainFormOnTaskbar = false. When I do want a child form to stay on top, then I make it modal or use fsStayOnTop.


Initially I though this question should be deleted, but then I decided to leave it here as an extension to the Embarcadero's documentation.

Gabriel
  • 20,797
  • 27
  • 159
  • 293
  • 1
    Info: This behavior was added in Delphi 2007 – Gabriel Mar 20 '21 at 12:15
  • It is generally a bad idea to use `ShowMainFormOnTaskbar=False`, a lot of VCL functionality needed for modern Windows integrations rely on it being `true` instead. I've always considered this a very bad design choice in the VCL, but it is what it is. To get the behavior you want, look at tweaking each Form's `PopupParent`/`PopupMode` properties, or override `CreateParams()` so set/clear the Form's owner window as desired. – Remy Lebeau Mar 20 '21 at 16:21
  • Thanks. I will look into "PopupParent/PopupMode". CreateParams should be called CreateProblems.... :) – Gabriel Mar 20 '21 at 17:35
  • Nothing discussed here changed anything for me. The secondary window appears on top of the main window and won't go behind it; it's always on top. Changing values don't seem to affect anything. the Form is made visible using "Show()", not "ShowModal()" – Yanick Rochon Jan 12 '23 at 14:06