Recent

Author Topic: How to create single page application for desktop  (Read 786 times)

bruce.button

  • Jr. Member
  • **
  • Posts: 59
How to create single page application for desktop
« on: August 05, 2022, 03:23:17 pm »
This is very much a beginner question, but I haven’t been able to find an answer or work it out. If I have an application with a few document windows, each of which shows one of the main areas of the app, how do I change seamlessly between them while keeping the main menu (and maybe a header area) the same? In other words, to make an application with the familiar type of interface that most desktop applications have these days.

As far as I can work out, I can't put the same menu on two different forms. I've tried putting the menu into a frame and putting the frame onto the two forms, but that doesn't seem to work. Using different menus is obviously not an option since one would have to repeat the same code on all of them; and it something on the menu changes you have to change it for the main menu on every form — that's definitely not DRY programming!

I'm accustomed to doing this in Filemaker Pro with different layouts, but I can't seem to find out how to do it in Lazarus.

Thank you in advance for the assistance!
« Last Edit: August 05, 2022, 03:27:12 pm by bruce.button »

dsiders

  • Hero Member
  • *****
  • Posts: 1077
Re: How to create single page application for desktop
« Reply #1 on: August 05, 2022, 04:17:43 pm »
This is very much a beginner question, but I haven’t been able to find an answer or work it out. If I have an application with a few document windows, each of which shows one of the main areas of the app, how do I change seamlessly between them while keeping the main menu (and maybe a header area) the same? In other words, to make an application with the familiar type of interface that most desktop applications have these days.

As far as I can work out, I can't put the same menu on two different forms. I've tried putting the menu into a frame and putting the frame onto the two forms, but that doesn't seem to work. Using different menus is obviously not an option since one would have to repeat the same code on all of them; and it something on the menu changes you have to change it for the main menu on every form — that's definitely not DRY programming!

I'm accustomed to doing this in Filemaker Pro with different layouts, but I can't seem to find out how to do it in Lazarus.

Thank you in advance for the assistance!

You can use TPageControl to display pages of content. Set its ShowTabs property to False to hide the navigation tabs if you prefer to use  menu items to activate the pages.

You can use a TFrame descendant for each page if you're comfortable with the extra effort required.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: How to create single page application for desktop
« Reply #2 on: August 05, 2022, 04:31:52 pm »
Here is a nice tutorial which shows everything from the first click

https://lazplanet.blogspot.com/2013/12/create-rich-text-editor-for-yourself.html

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: How to create single page application for desktop
« Reply #3 on: August 05, 2022, 04:57:47 pm »
If I have an application with a few document windows, each of which shows one of the main areas of the app, how do I change seamlessly between them while keeping the main menu (and maybe a header area) the same?

There are many solutions for it. You can use TPageControl or TFrame as suggest by dsiders. Or you can use MDI.

Learn more about MDI:
https://en.wikipedia.org/wiki/Multiple-document_interface
https://wiki.lazarus.freepascal.org/MultiDoc
https://wiki.freepascal.org/LMDI
https://forum.lazarus.freepascal.org/index.php?topic=45486.0

You can use TNotebook, example can be found in "Text File Demo #2". Not the best, you can even use TPanel. See the demo "simple transition effects". The demos can be get in the link below:
https://wiki.freepascal.org/Portal:HowTo_Demos#File_handling
« Last Edit: August 05, 2022, 04:59:56 pm by Handoko »

bruce.button

  • Jr. Member
  • **
  • Posts: 59
Re: How to create single page application for desktop
« Reply #4 on: August 05, 2022, 05:08:31 pm »
Thank you for all the helpful comments.

It seems to me that the TPageControl solution would best serve my needs. Would it be safe to use this for all the screens of a medium-sized application? I'm thinking of an application with about 20 screens, each one having a couple of grids drawing data from a database.

When I say "safe", I'm thinking about perhaps overloading the memory or something like that.

Thanks again!

Nicole

  • Hero Member
  • *****
  • Posts: 970
Re: How to create single page application for desktop
« Reply #5 on: August 05, 2022, 05:26:07 pm »
If you have 20 screens, it may be fine to work with frames. These frames allow you to develop without thousands lines of code to scroll.

F12 shows you the frame the same way as a form.

When you finish your work, you make your frames part of the pageControl by parent:

So the create event of your form will look like this (hope this works for Lazarus, I just dragged this code out of an old Delphi source):

  if Frame_BerichteAufMain = nil then begin
    Frame_BerichteAufMain:=TFrame_Berichte.Create(Form_Main);  // into storage
    Frame_BerichteAufMain.Parent:=Form_Main.TabSheet_Berichte; // display
                                           end; 

Handoko

  • Hero Member
  • *****
  • Posts: 5149
  • My goal: build my own game engine using Lazarus
Re: How to create single page application for desktop
« Reply #6 on: August 05, 2022, 05:36:42 pm »
@bruce.button

Basically there is not much memory usage difference using a TPageControl with many pages vs using many TForms.

If you know, using TForm, all the forms will be created and loaded into memory before you show them, unless you disable its auto-create behavior. Even if you close the form, actually it just go hiding, the memory is not freed. Unless you call TForm.Free or set caFree in the CloseAction variable.

Most of the computers nowadays have 4 GB of RAM or more. Memory usage of a form has very little impact in the whole system.

But if you really care, in your case I think you can consider to close the Dataset if you switch to other tab or closing the form, and open or reopen it when needed.

About TFrame, I don't against it. But just what dsiders said, it needs extra effort. It can be tricky in some cases, try it and you would know what I meant.

As a programmer, you should be open, try and learn everything if you have the time. Each of the components has its own pros and cons.
« Last Edit: August 05, 2022, 05:51:36 pm by Handoko »

bruce.button

  • Jr. Member
  • **
  • Posts: 59
Re: How to create single page application for desktop
« Reply #7 on: August 05, 2022, 06:01:20 pm »
Thank you again, @Nicole and @Handoko. Those are very helpful and informative comments.

I will try TPageControl with and without frames. As Handoko says, I need to learn!

 

TinyPortal © 2005-2018