1. Home
  2. Computing & Technology
  3. Delphi Programming

Raising TPageControl's OnChagning and OnChange events from code

By , About.com Guide

When setting ActivePage property for the TPageControl control, from code, the OnChanging and OnChange events are not triggered. By design, those events are only fired when a user clicks on a tab to activate the page (TabSheet) on a TPageControl.

One way to "fix" this behavior is to use the "protected hack" technique. By exposing the protected TPageControl's CanChange and Change methods you will be able to set the ActivePage from code while making sure OnChange and OnChanging fired.

~~~~~~~~~~~~~~~~~~~~~~~~~
type
   THackPageControl = Class(TPageControl) ;

procedure SetAsActivePage(tabSheet : TTabSheet) ;
begin
   if tabSheet.PageControl.ActivePage <> tabSheet then
   begin
     If THackPageControl(tabSheet.PageControl).CanChange then
     begin
         tabSheet.PageControl.ActivePage := tabSheet;
         THackPageControl(tabSheet.PageControl).Change;
     end
     else Abort;
   end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Moving the focus to the next Delphi edit control when MaxLength characters have been reached
« Fixing the "Transaction ... an object is in a zombie state"

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TPageControl
  6. Raising TPageControl's OnChagning and OnChange events from (Delphi) code

©2009 About.com, a part of The New York Times Company.

All rights reserved.