Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Delphi TPageControl "tab index" to "page index"?

I'm using a TPageControl, where certain pages are not visible.

This breaks the normal 1:1 mapping of the TabIndex and ActivePageIndex properties.

In most places I can use ActivePageIndex (or ActivePage itself) to get the current page, but I want a dynamic tooltip hint which requires me to determine which page is associated with a specific tab index.

If I call pageControl.IndexOfTabAt(X, Y), I get a Tab Index back, but I can't directly use that as an index into the Pages[] array, as some page tabs aren't visible.

I could explicity iterate through the pages, ignoring the visible ones, but it feels like there should be something in the VCL that does this for me already...?

like image 334
Roddy Avatar asked Nov 15 '22 13:11

Roddy


1 Answers

I you look in the source for TPageControl (ComCtrls.pas), there is a private method:

function TPageControl.PageIndexFromTabIndex(TabIndex: Integer): Integer;

that does what you want. But you can't call it (D2007), so (unfortunately) you have to copy the code.

like image 136
BennyBechDk Avatar answered Dec 23 '22 10:12

BennyBechDk