RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TTabControl.OnChanging Event

Occurs immediately before a new tab is selected.

Pascal
property OnChanging: TTabChangingEvent;
C++
__property TTabChangingEvent OnChanging;

Write an OnChanging event handler to take specific action immediately before the selected tab changes. Set the AllowChange parameter to false to prevent the change. 

Use an OnChanging event handler to prevent the user from leaving a tab setting until certain conditions have been met. An OnChanging event handler can also be used to save information about the current state of the tab control before it is changed by a new tab selection.

Note: The event is not called if you change the active page in code, for example, by setting the value of TPageControl. ActivePage.
 

C++ Examples: 

 

/*
This project requires a TPageControl, several TTabSheets (to
add sheets, right click the Page Control and select "New
Page" from the context menu), and a TEdit control on the
first tab sheet.  The user is not allowed to change to a new
page if the active page is "TabSheet1" and there is no text
in the Edit Control.
*/
void __fastcall TForm1::PageControl1Changing(TObject *Sender, bool &AllowChange)
{
  if (((TPageControl *)Sender)->ActivePage == TabSheet1)
    AllowChange = (!Edit1->Text.IsEmpty());
  else
    AllowChange = true;
  if (AllowChange == false)
  {
    MessageBeep(0);
    Edit1->SetFocus();
  }
}

 

Delphi Examples: 

{
This project requires a TPageControl, several TTabSheets (to
add sheets, right click the Page Control and select "New
Page" from the context menu), and a TEdit control on the
first tab sheet.  The user is not allowed to change to a new
page if the active page is "TabSheet1" and there is no text
in the Edit Control.
} 
procedure TForm1.PageControl1Changing(Sender: TObject; var AllowChange: Boolean);
begin
  if ((Sender as TPageControl).ActivePage = TabSheet1) then
    AllowChange := (Edit1.Text <> '')
  else
    AllowChange := True;
end;

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!