Recent

Author Topic: TPageControl & Co  (Read 1690 times)

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
TPageControl & Co
« on: February 22, 2021, 06:51:02 pm »
Another incompatibiliy on my way from Delphi 7 to Lararus (2.0.10, on and for Win x64 (only)).
Previously i used a subclassed TPageControl, and especially for the close button i applied ownerdraw.
That won't work any longer. Page control Ownerdraw id not supported by Lar., and close botton option n/a with Windows page control.

As seen in the forum, ATTabs had been alternatively recommended here.
Beneath tab icon and font coloer i need especially the close button, as well as tabsheet containers for, later, to place some controls onto them.

Tried the demo_tabs and tabs2 .. they compiled, but didn't show how to assign containers to the tabs (analoguos to the tabsheets).
So i tried the demo_tabs_as_pagecontrol .... does not compile ("the project has no main source file").
So i tried the demo_groups  ... does not compile either (as in demoform.pas there is a call APages.AddTab using a parameter list
differing from the parameter list of the procedure in the recent component version).
Sigh .... no working example so far.

So my question here: does anybody have a simple working example Laz. 2.0.10 / Windows for ATTab with each assigned tabsheets ?
(those might be panels or whatsoever, but not necessarily Forms. The number of tabs should be dynamically increasable/decreasable).

Final question so far: when closing a tab, might those containers and tabs be freed (and not only hidden) ?





Lazarus 3.2  FPC 3.2.2 Win10 64bit

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: TPageControl & Co
« Reply #1 on: February 22, 2021, 07:50:15 pm »
If you absolutely need the Close button you could try the TJvTabBar of the JVCL library. However, you should be warned: it is not compatible with the TPageControl. So, you will have to change your code.

First of all, the control contains only the tabs and needs a "PageList" container. There is a TJvPageList which uses TJvStandardPage containers for your controls. The component editor allows to add and remove pages at designtime. There is also a TJvNotebookPagelist which derives from TNotebook, but this is only available in the Lazarus port, not in the original Delphi version. And finally you need a control for painting the tab, either the TJvModernerTabBarPainter, or the TJvTabBarXPPainter.

The TabBar has an AutoFreeClosed property which destroys the tab and the attached page when the tab is closed.

You can install everything easily with the Online-Package-Manager. If you don't want all JVCL components you should open the JvclLaz item and check only the "jvpagecompsd.lpk" item. OPM will resolve the dependencies and install only those  JVCL packages needed.

There is a demo in the examples folder of the JVCLLaz installation - see screenshot.


lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl & Co
« Reply #2 on: February 22, 2021, 08:38:13 pm »
If you don't wnat to use a third party package, you can find a workaround (rather pointer to a workaround) for the close button on Windows in topic: PageControl button close

As for containers, I often use TFrame for that: one can design them as one would a form and they can work quite like an "embedded form" but without all the hassle of actual forms, and since they are the owner of the controls in them, these are freed when you free it.

HTH!
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.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: TPageControl & Co
« Reply #3 on: February 23, 2021, 10:57:25 am »
wp an lucamar, thank you a lot for your kind replies again!
Both hints appear to be possible. However i'm wondering you didn't mention this ATTabs at all which had been proposed so oftenly here in the forum when speaking about such page control requirements. It appears to be relatively compact and elaborated as well. And it appears to allow to have the close button for the active page only; that's fine imo.
No, it's no high prio thing, but i need to do a decision which component to use before being able to proceed with the further steps dealing with the real container's contents.
Need to dig further to find out how to connect a (variable number of) panel(s) or frame(s) to an individual tab.
lucamar, you used a collection of TFrames you did need to mainain yourself?

I'll try the TJvTabBar as well, hoping the frameworks overhead (for a single component) will not be so high after focusing onto the needed component only.



Lazarus 3.2  FPC 3.2.2 Win10 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl & Co
« Reply #4 on: February 23, 2021, 07:55:20 pm »
lucamar, you used a collection of TFrames you did need to mainain yourself?

More or less, yes. I create a frame for each kind of "tab" I need. Frames can be thought (and designed/coded) as "embedable" forms: you create one, put into it whatever controls you need, code event handlers for them, etc.

Then, in your main program, you put a page control, add the number of tabs you need  and insert each frame into its corresponding tab. Or you can do it in code, too, which allows you to control which frames/tabs exist at any given time, instead of having all of them all the time and show/hide them when needed.

Basically, it's the same concept as having several forms, only these "forms" (frames) are fully embedable in any other container, be it a real form, a panel, a tabsheet, etc.

For example, suppose you're building a multi-file text editor (see attached image). You can program a frame with a memo, a statusbar and whatever else you want as if it were a single-file editor and make your main program consist simply of a page control and a main menu with handlers/methods to create/destroy tabs, containing a "single-editor" frame, for each opened file. And you can build other frames to substitute search/replace dialogs which you could, for example, embed into a panel, etc., which allows you to have kind of complex "custom controls" to, say, replace dialogs on any application, or build complex forms with common groups of controls without too much work.

We use frames almost everywhere and I found them one of the best additions to the controls palette when they appeared. :)
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.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: TPageControl & Co
« Reply #5 on: February 24, 2021, 12:50:19 pm »
Hello lucamar,
thank you for your detailed and intersting response!
Yes ... but one will need such "handlers/methods to create/destroy" your panels/frames/... and unless you don't already have such in your portfolio (you'll probably have), you need to implement them (i would need to). At prog start those frames/panels cannot be statically created, because you don't know how many you will need at the end.
So my finding and idea for the next step is:

I meanwhile tried to use and adapt the ATTabs for my special needs and find it very easy to use. With a small code footprint (only a few couple of files needed) and easy to csutomize for your personal flavour.
That is very fine and smooth so far! So far i'm using, as proof of concept only, three statically defined panels. Those, passed at arguments within the create routine, will be presented as desired and are kept in the right order of assignment even after drag&drop operations.

For the real life containers (variable number 1...n  of frames/panels  ... or tabsheets) the idea behind is:
let the TPageControl itself do it's job as tabsheet factory, link the individual tabs to those tabsheets and that's all. I remember roughly it was mentioned somewhere in the forum: to connect a TTabControl minus Tabs (via: ShowTabs:=false) to a tab header control like atttabs. Both are working together fine, each doing what it can do best.
- The tabs from ATTabs ... small component, highly adaptable
- the data containers resp.  tabsheet collection engine from the native TPageControl
Hopefuly i'll find the time tomorrow to try that out.
What do you think of?

Lazarus 3.2  FPC 3.2.2 Win10 64bit

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TPageControl & Co
« Reply #6 on: February 24, 2021, 01:59:05 pm »
I haven't used ATTabs, so I've no opinion on them. What I have used is a combination of the standard TTabControl with a TNotebook and it worked quite well, though it needs some work (only some, not much) to keep both controls in synch. I assume the same would happen with any other "only tabs"+"only sheets" combination.

But then, if you want "cooler" tabs (as I assume ATTabs provide), that's a small price to pay :)
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.

d7_2_laz

  • Hero Member
  • *****
  • Posts: 511
Re: TPageControl & Co
« Reply #7 on: February 26, 2021, 10:04:16 am »
Hm. cooloer, it's more to preserve some special properties and behaviour  ..
Meanwhile, my proof (container-less ATTabs linked to TPageControls tab-less TabSheets  .. TPageControl as tabsheet collection engine; a TabSheet is simply passed as parameter to the AddTab procedure) worked fine and without problems. So i'm not aware of any reasons not to use this bypass.
Thanks a lot  lucamar and wp that you gave me the chance to exchange opinions!
Lazarus 3.2  FPC 3.2.2 Win10 64bit

 

TinyPortal © 2005-2018