Click here to Skip to main content
15,746,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't change mainform at runtime. I need it for user login in my app.

1 solution

Refer - Switch Application.Mainform at runtime and invoke MainformOnTaskBar cause flickering on Windows Taskbar[^].

The main form isn't something you're allowed to change in Delphi. You managed to find a way that appears to work half-way, but it's a hack. Stop doing that.

An application has only one main form, and it's the first form that finishes being created via CreateForm. If you need two radically different behaviors for the main form, then you can try a couple of techniques:

  • Define your two main forms as frames. Put all your functionality there. Then define a single form that will act as the parent of one of the two frames. Instead of switching the main form, simply destroy the frame and replace it with a new one.

  • Similar to the frame solution, but use forms instead. Create the forms, and set the Parent property to be the "real" main form. This will probably have a lower initial cost because you already have the two forms, but in my experience, re-parenting forms is more fragile than frames, which were designed for being child controls, so prefer the frame technique.

The flicker on the taskbar comes from one form disappearing and another appearing. With either technique above, there's always just one form, never two, so there's nothing to flicker.

This might help you.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900