Delphi Programming

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

Raising TPageControl's OnChagning and OnChange events from code

By Zarko Gajic, About.com

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"

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming

About.com Special Features

Delphi Programming

  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.