* * *

Author Topic: Get number of tab rows if TPageControl Multiline is active  (Read 611 times)

Romain

  • New member
  • *
  • Posts: 10
    • Attribute Changer Website
Get number of tab rows if TPageControl Multiline is active
« on: January 01, 2018, 09:38:14 pm »
In my application I have a TPageControl component and the Multiline property is set to True. Depending on the language strings I load, the caption length for the individual tabs are quite long and the tabs are created on two rows. This works as expected.

I this occurs, I need to resize the TPageControl's height itself to fit the content.

In Delphi VCL, there is a TPageControl.RowCount method to get the number of tab rows. I did not find a similar information in LCL for the TPageControl.

How can I get the number of active tab rows for a PageControl ?

Romain

wp

  • Hero Member
  • *****
  • Posts: 4217
Re: Get number of tab rows if TPageControl Multiline is active
« Reply #1 on: January 01, 2018, 10:08:21 pm »
There is no built-in property, but it can be calculated easily because there is function TabRect(pageindex) which returns the rectangle of the tab (that little rect with the tab title, not the page itself!). Just iterate through all pages and whenever the Top of the TabRect changes you found a new line:

Code: Pascal  [Select]
  1. function PageControlRowCount(APageControl: TPageControl): Integer;
  2. var
  3.   Rprev, Rcurr: TRect;
  4.   i: Integer;
  5. begin
  6.   Result := 1;
  7.   if not APageControl.Multiline then
  8.     exit;
  9.   Rprev := APageControl.TabRect(0);
  10.   for i:=1 to APageControl.PageCount-1 do begin
  11.     Rcurr := APageControl.TabRect(i);
  12.     if Rprev.Top <> Rcurr.Top then begin
  13.       inc(Result);
  14.       Rprev := Rcurr;
  15.     end;
  16.   end;
  17. end;

Needs to be adapted, of course, if the tabs are at the left or right.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Romain

  • New member
  • *
  • Posts: 10
    • Attribute Changer Website
Re: Get number of tab rows if TPageControl Multiline is active
« Reply #2 on: January 01, 2018, 10:22:24 pm »
I had the same idea but was struggling to find the TabRect function.

Thank you for your input !

wp

  • Hero Member
  • *****
  • Posts: 4217
Re: Get number of tab rows if TPageControl Multiline is active
« Reply #3 on: January 01, 2018, 10:33:25 pm »
was struggling to find the TabRect function.
That's the way I found it:

CTRL+Left-Click on the identifier "TPageControl" in your source code, and the IDE will open the file in which TPageControl is implemented. If you landed in the implementation part of this unit, press SHIFT-CTRL+UP to get to the interface part. Now you can scroll through the declaration of all properties and methods. Don't forget what's inherited from ancestors: scroll up to "TPageControl = class(TCustomTabControl)", CTRL+Left-Click on the identifier of its ancestor, TCustomTabControl. Now you see what is defined in TCustomTabControl, etc.

Unlike any written documentation, this method is absolutely up-to-date. Of course, as application developer you cannot access anything which is not declared as public or published.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

Romain

  • New member
  • *
  • Posts: 10
    • Attribute Changer Website
Re: Get number of tab rows if TPageControl Multiline is active
« Reply #4 on: January 01, 2018, 10:36:35 pm »
Cool, thank you very much !

Romain

Romain

  • New member
  • *
  • Posts: 10
    • Attribute Changer Website
Re: Get number of tab rows if TPageControl Multiline is active
« Reply #5 on: January 03, 2018, 07:16:23 am »
I found another solution for the Windows platform only :

NumRows := PageControl.Perform(TCM_GETROWCOUNT,0,0);

Romain
« Last Edit: January 03, 2018, 08:39:01 am by Romain »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus