Home > Back-end >  Delphi PageControl with TabSheet invisibleTabVisible := False;
Delphi PageControl with TabSheet invisibleTabVisible := False;

Time:11-16

I have a Form with a PageControl with 7 Tab. I want to see only some Tabs. On one side the Tab 0,1,2,3,4, and 5, and on the other side only the tab 6 and 7. I render then, in turn, invisible. I have a DBNavigator which change the DataSource in the procedure DBNavigatorClik to control the grid etc on the used tab.

As an exemple with 2 Tab

procedure TF_DatenErfassung.PageControl1Change(Sender: TObject);
 begin
  with (Sender as TPageControl) do
   case PageControl1.Tabindex of
  0:begin 
    DBNavigator1.DataSource:=F_ModuleTables.DS_MieteBezahlung;
   end;                                                                                                                 
  1:begin 
    DBNavigator1.DataSource:=F_ModuleTables.DS_T_JaresAbrechnung_Mieter;      
   end;
 end;{case}
end; 

In the FormActivate procedure I have this code:

if ModuleTables.T_TABLE.FieldByName('NrDossier').AsString[1]<>'X' then

{A}  begin
      PageControl1.Pages[0].TabVisible:=false;
      PageControl1.Pages[1].TabVisible:=true; {I want to work only on this Tab}
     end
    else
{B}  begin
      PageControl1.Pages[0].TabVisible:=true; {I want to work only on this Tab}
      PageControl1.Pages[1].TabVisible:=false;
    end;

When I am on the {A} on my form PageControl the Tab 1 is obviously the first one (in that case the only one) the Tab 0 is not visible and only the Tab 1 is visibled. But it seems that for the pageControl this is the Tab 0 and not 1 It just change the Tab Index; Is there a way to go around; I try to put in a

 PageControl1.ActivePageIndex:=1;

but it doesn't care. It seems to me that the Tab index is in reallity create when the page is created which doesn't make a problem but in my case it's make a problem. Is there a way to go around it without to recreate the all "wheel".

CodePudding user response:

You need to distinguish between Tabs and Pages. Tabs are the tabs of the visible pages. So if only one tab is visible that tab/page has always TabIndex = 0.

The case statement in PageControl1Change should act on PageControl1.ActivePageIndex instead of PageControl1.TabIndex.

  • Related