views:

281

answers:

3

I'm wondering so when I change state of CheckBox

CheckBox->Checked=false;

It calls CheckBoxOnClick Event , how to avoid it ?

+2  A: 

I hope there's a button solution but you could store the current event in a TNotifyEvent var, then set Checkbox.OnChecked to nil and afterwards restore it.

Remko
CheckBox->Checked=false is on button but it even calls onClick event. So I'll try it. Thank you.
nCdy
+5  A: 

You could surround the onClick event code with something like

if myFlag then
  begin
    ...event code...
  end;

If you don't want it to be executed, set myFlag to false and after the checkbox state's change set it back to true.

Holgerwa
yes ... :-S that's really easy. Don't know why I didn't made it myself >_<
nCdy
+4  A: 

Another option is to change the protected ClicksDisable property using an interposer class like this:

type
  THackCheckBox = class(TCustomCheckBox)
  end;

procedure TCheckBox_SetCheckedNoOnClick(_Chk: TCustomCheckBox; _Checked: boolean);
var
  Chk: THackCheckBox;
begin
  Chk := THackCheckBox(_Chk);
  Chk.ClicksDisabled := true;
  try
    Chk.Checked := _Checked;
  finally
    Chk.ClicksDisabled := false;
  end;
end;
dummzeuch