PageControlChanging (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

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. You are not allowed to change to a new page if the active page is "TabSheet1" and there is no text in the Edit Control.

Code

void __fastcall TForm1::PageControl1Changing(TObject *Sender, bool &AllowChange)
{
  if ((dynamic_cast<TPageControl *>(Sender))->ActivePage == TabSheet1)
	AllowChange = (!Edit1->Text.IsEmpty());
  else
    AllowChange = true;
  if (AllowChange == false)
  {
	MessageBeep(0);
	Edit1->SetFocus();
  }
}

Uses