Delphi .NET (2) Database (71) Delphi IDE (90) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
How to check or uncheck a TCheckBox without causing an OnClick event
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:
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?
Answer:
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);
var
NE: TNotifyEvent;
begin
with chk do
begin
NE := OnClick;
OnClick := nil;
Checked := b;
OnClick := NE
end;
end;
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|