Recent

Author Topic: Dynamically created tabsheets: select and resize  (Read 2876 times)

paxnet_be

  • Newbie
  • Posts: 3
Dynamically created tabsheets: select and resize
« on: July 16, 2021, 04:29:34 pm »
Hello guys,
Creating tabs at runtime is not a problem. But I have 2 issues with my tabsheets:

1. To select them, I must click 2 times on them except for the last created one, because after the first click, the focus goes to the last created one. Setting Tab = PgTabs.ActivePage (PgTabs is the parent PageControl of Tabs) does not help, nor other tries. (See the code in attachment).

2. Resizing the properties Left and Width of the sub elements of my tabsheets seem to be such a mess, that I do not understand, how to fix it (Again, see the code in attachment to help you understand my issues).  %)

Thanks for reply !

--------------------
Linux x86_64 GTK2, Lazarus 2.0.10, FPC 3.2.0

howardpc

  • Hero Member
  • *****
  • Posts: 3760
Re: Dynamically created tabsheets: select and resize
« Reply #1 on: July 16, 2021, 09:29:20 pm »
Note you are unlikely to get helpful replies if you do not attach a compilable project that shows the errors. A unit alone without .lfm means anyone who tries to help has to guess too much.

A better approach to dynamic creation of tabsheets is shown in the attached skeleton project.

Among many points that could be made, note that you have to be very careful when naming dynamically created components. It is all too easy to duplicate a name and immediately raise an exception.

Using OnResize of a form to control layout dynamically is usually doomed except when the layout is very simple indeed.

 Far better to use the LCL's built-in anchoring, aligning, childsizing and autosizing capabilities, which have debugged most of the complexity and heavy lifting for you already.

paxnet_be

  • Newbie
  • Posts: 3
Re: Dynamically created tabsheets: select and resize
« Reply #2 on: July 17, 2021, 08:19:47 am »
Thank you howardpc.

Your approach is very interesting.

In the status of my project, It is surely worth to try it. I will also take a closer look at the LCL's built-in capabilities.
--------------------
Linux x86_64 GTK2, Lazarus 2.0.10, FPC 3.2.0

paxnet_be

  • Newbie
  • Posts: 3
Re: Dynamically created tabsheets: select and resize
« Reply #3 on: July 21, 2021, 05:34:04 pm »

Hello again guys.

With the great advises of howardpc, I was able to find the right settings for my project.   :D

Here is what I have learned, among other things:

1. To select the right tabsheet, set:
      CurrentTabSheet.Parent.Activepage := Sender as TTabSheet;

2. Use BorderSpacing and AnchorSide to align the child components of the CurrentTabSheet.

3. For Left, Height and Width of the concerned component, do not use the main form as referencing control but the parent of the component.

4. At maximized main form, before you create the first tabsheet, get Height and Width of the parent PageControl, otherwise the tabsheet will take the parent PageControl with normal sizes as reference. The same is true when you resize the form with already created tabsheets.

For who is interested of working with tabsheets at runtime, please find in attachment the zipped files of the working interface for my project.

Greetings.
--------------------
Linux x86_64 GTK2, Lazarus 2.0.10, FPC 3.2.0

 

TinyPortal © 2005-2018