DelphiFAQ Home Search:
General :: Programming :: Delphi :: VCL
About the Delphi VCL (Visual Component Library)


This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Only the 40 most recently viewed articles are shown.
You can see the full list here.

Featured Article

How to check or uncheck a TCheckBox without causing an OnClick event


My application needs to update a few checkboxes and other controls but no events shall be fired by these changes. How can I prevent those OnClick() and other events?


Before you update the control(s), you need to ..

  • assign NIL to the event handler property for each control
  • then update the control
  • reassign the correct event handler - as shown in the code below.

    If several controls share one event handler, it would be more elegant to have a boolean flag which you temporarily set to false and the event handler(s) would check this flag before they do anything.

    procedure SetCheckBox(chk: TCheckBox; b: boolean);
       NE: TNotifyEvent;
     begin { SetCheckBox }
       with chk do 
         NE := OnClick;
         OnClick := nil; 
         Checked := b; 
         OnClick := NE
       end; { with chk } 
     end; { SetCheckBox } 
    You don't like the formatting? Check out SourceCoder then!
  • Generated 8:01:21 on May 25, 2018