Recent

Author Topic: What is the purpose of TNotebook, TPageControl, TTabControl?  (Read 4044 times)

OC DelGuy

  • Full Member
  • ***
  • Posts: 218
  • 123
What is the purpose of TNotebook, TPageControl, TTabControl?
« on: February 06, 2021, 10:19:17 am »
What do these controls do?  Under what circumstances would a programmer use these controls?
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

MarkMLl

  • Hero Member
  • *****
  • Posts: 8563
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #1 on: February 06, 2021, 10:45:01 am »
They allow you to move between various groups of control. You could have worked that out in five minutes from the IDE.

Or do you mean "What is the distinction and what are the recommended use cases"? That's a rather more complex question and there's been at least one breaking change as functionality has been adjusted. Hopefully one of the LCL gurus will be along shortly to give us chapter and verse, meanwhile I suggest

https://lazarus-ccr.sourceforge.io/docs/lcl/extctrls/multi-pagecontrols.html

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #2 on: February 06, 2021, 10:50:42 am »
What do these controls do?  Under what circumstances would a programmer use these controls?
TPageControl: You can group controls on different pages. Every page has its own controls. There are tabs to select a given page.
TTabControl: Looks like TPageControl, but the same controls are used by all pages. Suppose a multi-file editor: The TabControl contains the editor control, and every page loads an associated file into it.
TNotebook: some kind of page control (i.e. each page has its own controls), but has no tabs. You can use other controls to switch between pages (combobox, treeview etc).

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #3 on: February 06, 2021, 01:57:07 pm »
[...] meanwhile I suggest
https://lazarus-ccr.sourceforge.io/docs/lcl/extctrls/multi-pagecontrols.html

That particular page of the documentation is not only extremely confusing but also extremely confused: a lot of what it says is simply false or obsolete or doesn't work, like e.g. when it talks about images and TTabControls, etc.

I would rather suggest you (the OP) do what I did: test each control to see what it can do or not do. I even wrote some rather extensive notes with a view to replace that page of the docs, but I Iost the pendrive where it was stored and by that time I had already settled on TPageControl for almost everything I ever need.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8563
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #4 on: February 06, 2021, 02:20:44 pm »
That particular page of the documentation is not only extremely confusing but also extremely confused: a lot of what it says is simply false or obsolete or doesn't work, like e.g. when it talks about images and TTabControls, etc.

I would rather suggest you (the OP) do what I did: test each control to see what it can do or not do. I even wrote some rather extensive notes with a view to replace that page of the docs, but I Iost the pendrive where it was stored and by that time I had already settled on TPageControl for almost everything I ever need.

Hmm. I've certainly seen worse documentation, but would agree that "probably intended" is a definite red flag.

I can't remember the details, but way back something happened which I /think/ involved the LCL developers realising that their implementation of TPageControl wasn't really compatible with Delphi's, renaming it to TNotebook and redoing TPageControl from scratch (a breaking change which complicated program maintenance if trying to support multiple Lazarus/LCL versions). I don't think that that's helped the documentation situation... and considering the amount of really old Delphi stuff around it might even be worth considering that v1 (i.e. for Win-16) had "TabbedNotebook" and "TabSet" while v3 (i.e. for Win32) had "PageControl" and "TabControl"... presumably inherited from what was in the system DLLs.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
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: 5529
  • My goal: build my own game engine using Lazarus
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #5 on: February 06, 2021, 07:02:27 pm »
Quote
What is the purpose of TNotebook, TPageControl, TTabControl?

I think you should also include THeaderControl.

They all have some overlapped features, some of them can be customized to look a bit more like the other. For beginners, one should start with TPageControl, it (I believe) has the most features and relatively easy to use.

I usually will use TNotebook to avoid creating several forms, because sometimes it is easier to have all the things inside a single form than separate them into multiple forms. For example you can see this demo:
https://forum.lazarus.freepascal.org/index.php/topic,39769.msg274036.html#msg274036

I prefer to use TPageControl for user configuration forms. It groups items into pages. So users can easier to find the item s/he is looking for.

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #6 on: February 06, 2021, 10:28:19 pm »
I extended the related wiki articles by more information which hopefully makes it clearer what these controls are good for:

* https://wiki.lazarus.freepascal.org/TPageControl
* https://wiki.lazarus.freepascal.org/TTabControl
* https://wiki.lazarus.freepascal.org/TNotebook

MarkMLl

  • Hero Member
  • *****
  • Posts: 8563
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #7 on: February 06, 2021, 10:36:19 pm »
@wp Thanks for that.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

OC DelGuy

  • Full Member
  • ***
  • Posts: 218
  • 123
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #8 on: February 08, 2021, 12:11:44 am »
I extended the related wiki articles by more information which hopefully makes it clearer what these controls are good for:

* https://wiki.lazarus.freepascal.org/TPageControl
* https://wiki.lazarus.freepascal.org/TTabControl
* https://wiki.lazarus.freepascal.org/TNotebook
Yes, but why would I need different controls on different pages?  Why would I want to separate controls in a program?  Do the controls become inactive when the page they're on is not active?
Could I maybe put controls for a database of "insects" and then a database of "trees" on another page and when the user wants insects he gets that particular page?
Does the user even "see" the pages?
Are pages there for the programmer to better organize his program (This page has all the controls dealing with users from the US, and this other page has all the controls dealing with users from France)?  Or for the user to have access to the certain parts of the program he's allowed to access (this page has controls used by admins in a chat room and this other page is for controls used by regular chatters)?
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #9 on: February 08, 2021, 12:41:20 am »
Yes, but why would I need different controls on different pages?  Why would I want to separate controls in a program? 
Look at the IDE, menu "Tools" > "Options". What you see in the right part of the form is a TNotebook with many pages. Whenever you select an item in the tree the corresponding notebook page is activated. This way a huge amount of information can be displayed within a single form. Without the notebook, the form would be extremely crowded, or the information would have to be distributed onto a large number of separate forms which are very inconvenient for the user (requiring a huge multi-level menu which is painful to use).

Do the controls become inactive when the page they're on is not active?
Only the controls on the visible page are "active" (I suppose you mean: "the user can select them and edit the provided information").

Could I maybe put controls for a database of "insects" and then a database of "trees" on another page and when the user wants insects he gets that particular page?
I don't know exactly what you mean here. But suppose you have a database with names and properties of animals and plants, you could create a page for "insects", another page for "mammals", other one for "trees", yes. If all this information can be displayed with the same controls (an Edit for "common name", another edit for "scientifc name", a listbox for "countries", etc) then you can use a TTabControl, filter the database for "insects", "mammals" or "trees" and populate the controls on the TabControl correspondingly whenever another tab is selected. When "insects", "mammals" and "trees" require different controls, you should use a TPageControl where every page can be populated with its own controls. Both TTabControl and TPageControl have a row of tabs - in this example they would be labeled "Insects", "Mammals", "Trees", and the user can click on these tabs to see the page with the corresponding controls.

Are pages there for the programmer to better organize his program
For both programmer and user. The "Tools" > "Options" dialog is much more easier to use than a huge menu with inidivdual forms.

Or for the user to have access to the certain parts of the program he's allowed to access (this page has controls used by admins in a chat room and this other page is for controls used by regular chatters)?
Not automatically, but of course such restrictions can be coded.

Why don't you simply check it out? Create a new project, add a TPagecontrol, right-dick on the pagecontrol and add several pages. Add some controls to the page that you see. Click on one of the tabs to see another page and add controls to it too. Finally compile and run and play with it. You will immediately understand how a PageControl works. Then repeat with the TabControl and see the difference.

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #10 on: February 08, 2021, 06:47:21 am »
Note also that while you can have different controls on different pages (with TPageControl and TNotebook) nothing prevents you from having the same control(s) on all of them. You've probably seen lots of programs like that: a browser, a "tabbed" text editor, etc. Or you can, yes, have several databases (or different parts of the same), opened on different tabs, even if they all have the same controls; not much different than, say, a web browser, is it?

One very useful "control" for this cases is TFrame: you design the base "page" UI in a TFrame and then, in your main program, embed a frame in each page you create. That way you have a place where you can design and code your UI as if it were a single "form" which can be replicated (either at design- or run-time) into as many pages as you need.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

OC DelGuy

  • Full Member
  • ***
  • Posts: 218
  • 123
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #11 on: February 10, 2021, 08:18:37 pm »
Why don't you simply check it out? Create a new project, add a TPagecontrol, right-dick on the pagecontrol and add several pages. Add some controls to the page that you see. Click on one of the tabs to see another page and add controls to it too. Finally compile and run and play with it. You will immediately understand how a PageControl works. Then repeat with the TabControl and see the difference.
I did.  I put these controls on the form and started running them.  It seems I wasn't able to set them up properly, so I didn't learn much.  That's why I posted here.  That's how I've learned most of the controls I know so far.  The one's I can't figure out are the ones you hear about here on the forum. :)
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13484
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #12 on: February 10, 2021, 11:23:56 pm »
Hmmm.... I am willing to help you but the problem is for me that when I create TPageControl, TTabControl and TNotebook sample projects for you I don't know whether they touch the issues that you see. When you say "It seems I wasn't able to set them up properly, so I didn't learn much" I am helpless because I do not know what you did and what was happening and what you were expecting. Please be more specific.


MarkMLl

  • Hero Member
  • *****
  • Posts: 8563
Re: What is the purpose of TNotebook, TPageControl, TTabControl?
« Reply #13 on: February 11, 2021, 09:17:54 am »
Hmmm.... I am willing to help you but the problem is for me that when I create TPageControl, TTabControl and TNotebook sample projects for you I don't know whether they touch the issues that you see. When you say "It seems I wasn't able to set them up properly, so I didn't learn much" I am helpless because I do not know what you did and what was happening and what you were expecting. Please be more specific.

I don't know to what extent this is a coding problem. I'm slightly troubled by OP's

Quote
Yes, but why would I need different controls on different pages?  Why would I want to separate controls in a program?

If he doesn't have enough experience to have come across tabbed notebooks (and untabbed wizards etc.) then no amount of coding example is going to help him.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018