Lazarus

Programming => LCL => Topic started by: Nimral on April 01, 2021, 02:06:59 pm

Title: Swapping Application Main Form
Post by: Nimral on April 01, 2021, 02:06:59 pm
Hi all,

I have an existing application where the GUI consists of one form and multiple "Views". I implemented this years ago by having one main form, and a panel holding the controls for each view, and I switch the panel visibility so only one is visible at a time. Drawback: it is impossible to use the Lazarus IDE for form/view editing, because the views are all positioned on top of each other. I worked around this by placing them side by side in the forms editor and adjusting their positions in code when I switch from panel to panel.

I'd prefer to have multiple forms, but don't know how to switch from one to another. AFAIK terminating the main form (the one loaded by the .lpr file) will terminate the application.

Does anyone know a not-too-hacky approach to switch forms and passing control back and forth between them, or am I better off staying with what I have now?

Thnx, Armin.
Title: Re: Swapping Application Main Form
Post by: GetMem on April 01, 2021, 02:29:03 pm
@Nimral

Dynamically created TFrames is what are you looking for. Just do a quick forum search, I'm sure there are plenty of example available. In this case a frame is a "view".
Alternatively you can achieve the same effect with a TPageControl. On form create set ShowTabs property to false. Then switch between "views" with PageControl1.ActivePageIndex.
Title: Re: Swapping Application Main Form
Post by: MarkMLl on April 01, 2021, 02:46:07 pm
I agree with @GetMem: use frames if possible, but I'd caution that once you're put a frame onto a form at design-time you should treat it as r/o.

You can obviously bring panels to the front/top, or minimise their size (edited: I specifically mean reduce to 5x5 px or similar, I don't mean "minimise" as you can with a window) at design time. However I suggest that even if you stick to having controls created (at design time) directly onto the main form you could use a tabbed notebook or similar, and only enable the page you want the user to see. Works for me.

MarkMLl
Title: Re: Swapping Application Main Form
Post by: Handoko on April 01, 2021, 03:31:15 pm
Or maybe using a TNotebook. In the section "File handling" in the link below you can find "Text file demo" showing how to use TNotebook:

https://wiki.freepascal.org/Portal:HowTo_Demos
Title: Re: Swapping Application Main Form
Post by: Nimral on April 01, 2021, 04:11:31 pm
Thank you all three, you gave me plenty of hints to fill my next days checking your suggestions out. From what I saw at first glance, TPageControl is the first one I should give a try.

Thanks again,

Armin.
TinyPortal © 2005-2018