In the Delphi documentation about the TCustomForm.FormStyle a note is added that states: "It is not advisable to change FormStyle at runtime."
I would like to know why it is not advisable to change the formstyle at runtime. Is it not advisable from a user interface point of view or are there some technical issues that could occur? And what kind of issues could occur after changing the formstyle at runtime?
Use case
We would like to improve the multi monitor support of our MDI application. Currently all child windows are opened within the main window (MDI Parent window). What the users would like is to be able to open/move a child window outside the main window so that the child window will be opened as separate floating window that can be located anywhere at the Windows desktop.
I have seen examples of this functionality in Adobe Photoshop, Google chrome and Microsoft Internet Explorer. (Tabs can be moved from the tabbar and will be opened in a separate floating window)
Changing the FormStyle
at runtime from fsNormal
to fsMDIform
or fsMDIChild
requires re-creating the window handle, and that in turn requires the re-creation of all window handles for all controls on your form. There are lot's of things outside of Delphi's control when that happens: maybe you're using some 3rd party control that relies on some Windows control yet the 3rd party control doesn't know how to save it's state. The user would loose all work when the Window handle is re-created.
Fortunately you can work around the problem:
Most likely it's because a form style change will lead to window handle re-creation. And this will force re-creation of the handles of all child windows too.
Window re-creation is by and large something that can happen without you noticing. But there are controls which have problems with re-creation. I've suffered from this with the toolbar control in the past, for example. More recent versions of Delphi are more resilient to re-creation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With