Several ways to do that.
1. A small procedure in your toolbox:
procedure CheckBoxPreset(ACheckBox: TCheckBox; AChecked: Boolean);
var
LBckEvent: TNotifyEvent;
begin
LBckEvent := ACheckBox.OnClick;
ACheckBox.OnClick := nil;
ACheckBox.Checked := AChecked;
ACheckBox.OnClick := LBckEvent;
end;
2. Use a class helper
type
TCustomCheckBoxHelper = class helper for TCustomCheckBox
procedure ForceChecked();
procedure ForceUnchecked();
procedure Preset(AValue: Boolean);
end;
Implementation
procedure TCustomCheckBoxHelper.ForceChecked();
begin
with Self do
FState := cbChecked;
end;
procedure TCustomCheckBoxHelper.ForceUnchecked();
begin
with Self do
FState := cbUnchecked;
end;
procedure TCustomCheckBoxHelper.Preset(AValue: Boolean);
begin
if AValue then
ForceChecked()
else
ForceUnchecked();
end;
Then access the helper methods like a regular method of checkbox:
cbMyCheckbox.ForceChecked();
cbMyCheckbox.ForceUnchecked();
cbMyCheckbox.Preset(True);