Jump to content
Henry Olive

Page Control

Recommended Posts

Good Day,

I have a PageControl with 4 tabsheets

When i move from a tabsheet (for examp.  Tabsheet2)  to another tabsheet ( for examp. Tabsheet3)

I want to find out **from which TabSheet**  i came to new TabSheet

According to above example tabsheet names i want to find out TabSheet2

Thank You
 

 

Share this post


Link to post

TPageControl has two events for changing pages:

  1. OnChanging and
  2. OnChanged.

Use the first to get the old tabsheet and the second to get the the new one.

Share this post


Link to post
7 hours ago, Henry Olive said:

When i move from a tabsheet (for examp.  Tabsheet2)  to another tabsheet ( for examp. Tabsheet3)

I want to find out **from which TabSheet**  i came to new TabSheet

Unfortunately, the underlying Win32 tab control which TPageControl is built on does not provide that information natively.  The TPageControl.OnChanging event is fired BEFORE the active TabSheet changes, and the TPageContro.OnChange event is fired AFTER the active TabSheet is changed.  So, you will have to keep track of the previous TabSheet in your own code, eg:

 

private
  PreviousTabSheet: TTabSheet;

procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean);
begin
  PreviousTabSheet := PageControl1.ActivePage;
  AllowChange := True;
end;

procedure TForm1.PageControl1Change(Sender: TObject);
begin
  if PreviousTabSheet <> nil then
  begin
    // use PreviousTabSheet as needed...
    PreviousTabSheet := nil;
  end;
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×