Hi,

Thanks for opening.

I'm writing a "fill-out" form in Delphi, with each section enclosed in its own tab, using TPageControl and TTabControl.
When the info on each tab has passed validation rules (all working fine), the next button is enabled and the tab can be moved on.

When the form runs, all the tabs which have not been used, i.e. all of them, are highligted. When 'Next' is clicked the tab will move on and the tab just used is highdimmed.

I have stripped this code down to it's bare bones and it still won't work: basically, it will move on the first time, and highdim correctly - but each subsequent time it will move on, but highdim the NEXT tab.

I can see nothing wrong with the code - can anyone spot any glaring errors.

This is my procedure. The showmessages show which tab is being worked on - again it works the first time but goes doo-lally the second.

procedure Tform_bookvisit.button_nextandbookClick(Sender: TObject);
begin
  ShowMessage('current index '+inttostr(pgctrl_bookvisit.tabindex));
TTabSheet(pgctrl_bookvisit.Controls[pgctrl_bookvisit.tabindex]).Highlighted:=false;
  ShowMessage('just highdimmed index '+inttostr(pgctrl_bookvisit.tabindex));
pgctrl_bookvisit.SelectNextPage(true);    //:=pgctrl_bookvisit.TabIndex+1;
  ShowMessage('just advanced index to '+inttostr(pgctrl_bookvisit.tabindex));
end;

Can anyone help? Can send the whole lot if anyone wants to try with it.

Many Thanks in advance,

Don

Try the following code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls;

type
  TForm_bookvisit = class(TForm)
    PgCtrl_bookvisit: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Button_nextandbook: TButton;
    Memo1: TMemo;       // Placed on the Form outside the PageControl
    Label1: TLabel;     // Placed on the TabSheet1
    Label2: TLabel;     // Placed on the TabSheet2
    Label3: TLabel;     // Placed on the TabSheet3
    procedure Button_nextandbookClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form_bookvisit: TForm_bookvisit;

implementation

{$R *.dfm}

procedure TForm_bookvisit.Button_nextandbookClick(Sender: TObject);
var
  I:       Integer;
  J:       Integer;
begin
  I := pgctrl_bookvisit.ActivePageIndex;
  J := pgctrl_bookvisit.PageCount-1;
  Memo1.Lines.Add('LastPageIndex= '+IntToStr(J) + ';    ActivePageIndex= '+IntToStr(I));
  if ((J-I)>0) then
    Inc(I)
  else
    I := 0;
  pgctrl_bookvisit.ActivePageIndex := I;
  Memo1.Lines.Add('LastPageIndex= '+IntToStr(J) + ';    ActivePageIndex= '+IntToStr(I));
  Memo1.Lines.Add('__________________________________________');
end;

end.
This question has already been answered. Start a new discussion instead.