Link to home
Start Free TrialLog in
Avatar of boardtc
boardtcFlag for Ireland

asked on

2 possible interfaces runtime

I have to create a program with 2 possible interfaces depending on a registry setting. A lot of the code is common. The MainForm is different. I obviously cannot set Application.MainForm but any potential pitfalls that anyone knows?
Avatar of Epsylon

In the dpr file of the project you can decide which form to create:

  if SomeRegistrySetting then
    Application.CreateForm(TForm1, Form1)
    Application.CreateForm(TForm2, Form2);
one easy way is to set application.MainForm, to a blank form. Then depending on the interface, you create the correct form, set its borderStyle to bsNone, set its Align to alClient and Parent it to the main form.
I'm using the same logic as Epsylon in some of my projects, and it works without any problems... The main form is automatically the one that is created first.

Epsylon is right. I realy can't imagine more easy way to switch main form.
A nasty hack solution is to create two panels on your main form, one for each of your interfaces. Then just make whichever one you need active (and visible). Not overly nice but it'll work and you don't have to worry about code duplication

The Neil =:)
Avatar of boardtc


Epsylon, sounds like thee is no pitfalls though from reading some of the other mails you wouldn;t think so!

Cheers, Tom.
Sorry, must have missed a notification here....

I'm not sure what you mean, Tom. Of course there will be other ways but I would choose the one I mentioned above.
For the common code I would create separate units which can be used in both interfaces.
Avatar of boardtc


I was doing it the way you mentioned Epsylon, I was womdering if there were any pitfalls to doing it and my comment relected somee of the othere thinking there was. I guess there isn't. Answer to grade. Tom.
Avatar of Epsylon

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boardtc


Answer accepted