0

There are various tricks in the VCL world to set a checkbox state with out triggering a change event, for example:

  yourCheckBox.Perform(BM_SETCHECK, 1, 0)

Or less elegantly removing the event, change the state and restoring the event.

My question is, are there any recognized methods to change the state of a checkbox in firemonkey without causing an OnChange event?

rhody
  • 2,274
  • 2
  • 22
  • 40

1 Answers1

0

I discovered this answer (Change CheckBox state without calling OnClick Event) that uses helper classes to implement the feature. This is VCL and Firemonkey friendly with the caveat that one can only have one helper class per class. This means if someone else also has a helper class for TCheckbox then only one of the helper classes will be used. The alternative method and one that avoids the helper class issue (pity) is to write a separate method such as:

procedure TfrmMain.setCheckBox (chkBox : TCheckBox; state : boolean);
var OnChangeHandler : TNotifyEvent;
begin
  OnChangeHandler := chkBox.OnChange;
  chkBox.OnChange := nil;
  chkBox.IsChecked := state;
  chkBox.OnChange := OnChangeHandler;
end;
Community
  • 1
  • 1
rhody
  • 2,274
  • 2
  • 22
  • 40