Unselectable Tab

Is there any way at all of making a tab on a tabbed notebook unselectable? i.e not allowing the user to click and see its contents?

Yes, this is possible. The simplest way to do it is to remove the relevant page of the TabbedNotebook with something like:


  with TabbedNotebook do

  Pages.Delete(PageIndex);


and retrieve the deleted page (if necessary) by reloading the Form. Disabling (rather than deleting) is a bit trickier because you have to set up a loop in the Form's Create procedure to assign names to the tabs of the TabbedNotebook. Something like:


  J := 0;

  with TabbedNotebook do

  for I := 0 to ComponentCount - 1 do

  if Components[I].ClassName = 'TTabButton' then

  begin

  Components[I].Name := ValidIdentifier(TTabbedNotebook(

  Components[I].Owner).Pages[J]) + 'Tab';

  Inc(J);

  end;


where ValidIdentifier is a function which returns a valid Pascal identifier derived from the Tab string:


  function ValidIdentifier (theString: str63): str63;

 {----------------------------------------------------------}

 { Turns the supplied string into a valid Pascal identifier }

 { by removing all invalid characters, and prefixing with }

 { an underscore if the first character is numeric. }

  {----------------------------------------------------------}

  var

  I, Len: Integer;

  begin

  Len := Length(theString);

  for I := Len downto 1 do

  if not (theString[I] in LettersUnderscoreAndDigits) then

  Delete(theString, I, 1);

  if not (theString[1] in LettersAndUnderscore) then

  theString := '_' + theString;

  ValidIdentifier := theString;

  end; {ValidIdentifier}


A Tab of the TabbedNotebook may then be disabled with


  with TabbedNotebook do

  begin

  TabIdent := ValidIdentifier(Pages[PageIndex]) + 'Tab';

  TControl(FindComponent(TabIdent)).Enabled := False;

  { Switch to the first enabled Tab: }

  for I := 0 to Pages.Count - 1 do

  begin

  TabIdent := ValidIdentifier(Pages[I]) + 'Tab';

  if TControl(FindComponent(TabIdent)).Enabled then

  begin

  PageIndex := I;

  Exit;

  end;

  end; {for}

  end; {with TabbedNotebook}


and you could re-enable all tabs with:


  with TabbedNotebook do

  for I := 0 to Pages.Count - 1 do

  begin

  TabIdent := ValidIdentifier(Pages[I]) + 'Tab';

  if not TControl(FindComponent(TabIdent)).Enabled then

  TControl(FindComponent(TabIdent)).Enabled := True;

  end; {for}