CheckBox Control

Hierarchy: TObject - TPersistent - TComponent - TControl - TWinControl - TButtonControl - TCustomCheckBox - TCheckBox

The check box component provides a switch or toggle for a user to set an on or off state.

For example:

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
 if CheckBox1.Checked then Edit1.Text:='checked'
 else
 Edit1.Text:='not checked';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 if CheckBox1.Checked then Edit1.Text:='checked'
 else
 Edit1.Text:='not checked';
end;

 

Significant Properties

Alignment

Set to left or right alignment to move position of caption.

AllowGrayed

adds a third state to the on/off true/false pair. For example: AllowGrayed:=true;

Checked

As in code above. 

State

There are three states for which an application can test: cbUnchecked, cbChecked, cbGrayed. For example: 

procedure TForm1.CheckBox1Click(Sender: TObject);
 begin
  if CheckBox1.State=cbChecked then Edit1.Text:='checked'
  else
   if CheckBox1.State=cbUnchecked then Edit1.Text:='not checked'
   else
    if CheckBox1.State=cbGrayed then Edit1.Text:='grayed'
end;

The application can take whatever action is required from the state of the check box, for example setting a variable or setting a value to write to a file.

Back to Tutorial

Back to Palette List