Recent

Author Topic: Swapping Application Main Form  (Read 966 times)

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Swapping Application Main Form
« 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.
« Last Edit: April 01, 2021, 02:16:57 pm by Nimral »
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

balazsszekely

  • Guest
Re: Swapping Application Main Form
« Reply #1 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.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6682
Re: Swapping Application Main Form
« Reply #2 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
« Last Edit: April 01, 2021, 02:49:28 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: Swapping Application Main Form
« Reply #3 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

ArminLinder

  • Sr. Member
  • ****
  • Posts: 314
  • Keep it simple.
Re: Swapping Application Main Form
« Reply #4 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.
Lazarus 3.3.2 on Windows 7,10,11, Debian 10.8 "Buster", macOS Catalina, macOS BigSur, VMWare Workstation 15, Raspberry Pi

 

TinyPortal © 2005-2018