Sign in Join
Wiki copytemporary

TCheckGroup: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11A **TCheckGroup** ![](/wiki-images/1/1b/Tcheckgroup.png) is a control that comprises a group of [[TCheckBox]] items physically and logically grouped together on a container component.
22
33## Usage
44
55To use a TCheckGroup on a [[TForm|form]], you can simply select it on the [[Standard tab]] of the [[Component Palette]] and place it by clicking on the form.
66
77### Small example
88
99It changes the background color of a form. This color is determined by adding the individual color components:
1010
1111- create a new application and place a TCheckGroup on your form
1212- in the object inspector change the property *Name* of *CheckGroup1* to *cgRed* and the caption to *Red*
1313- add the checkboxes for *cgRed*:
1414 - in the object inspector select the property *Items* of *cgRed*
1515 - click on the button \[...\], the character chain editor opens
1616 - write among one another *1 2 4 8 16 32 64 128* and complete the entry with the *OK* button
1717- copy this TCheckGroup by right click *cgRed* in the form and click on *Copy*
1818- right-click the form and click on *Insert*, which creates TCheckGroup named *cgRed1*
1919- now change the *Name* of *cgRed1* to *cgGreen* and the *Caption* to *Green*
2020- insert even a TCheckGroup and change the name to *cgBlue* and the caption to *Blue*
2121- whenever a CheckBox is clicked, the color will change:
2222 - in the object inspector create the *OnItemClick* event handler of *cgRed* by clicking the button \[...\] next to the event *OnItemClick*
2323 - select for *cgGreen* and *cgBlue* also this event handler, by choosing each next to the event *OnItemClick* ComboBox *cgRedItemClick*
2424 - write following code in the event handler:
2525
2626``` pascal
2727procedure TForm1.cgRedItemClick(Sender: TObject; Index: integer);
2828var
2929 i, c: Integer;
3030begin
3131 c := $000000; // first the color is black
3232 for i:=0 to 7 do begin // test Items 0..7 of all Checkgroups
3333 if cgRed.Checked[i] then c := c + 1 shl i; // amount of red $000000..$0000FF
3434 if cgGreen.Checked[i] then c := c + 1 shl (i + 8); // amount of green $000000..$00FF00
3535 if cgBlue.Checked[i] then c := c + 1 shl (i + 16); // amount of blue $000000..$FF0000
3636 end;
3737 Color := c;
3838end;
3939```
4040
4141- start your program, it could look like:
4242
43-<figure>
44-<img src="ExampleTCheckGroup.png" title="ExampleTCheckGroup.png" />
45-<figcaption>ExampleTCheckGroup.png</figcaption>
46-</figure>
43+![](/wiki-images/c/ca/ExampleTCheckGroup.png)
4744
4845## Accessing the Check Boxes
4946
5047Each item in the TCheckGroup has a Checked property, to set them all to checked do
5148
5249``` pascal
5350for i := 0 to MyCheckGroup.items.Count-1 do // check all the categories we found.
5451 MyCheckGroup.Checked[i] := true;
5552```
5653
5754You can add items at run time by using TCheckGroup.Items, its a TStrings list. To add an new checkbox to the set, just do MyCheckGroup.Items.add('CheckThis'); Similarly, to remove all items, clear the list, MyCheckGroup.Items.clear;
5855
5956## See also
6057
6158- [[doc:lcl/extctrls/tcheckgroup.html|TCheckGroup doc]]
6259- [[TCheckBox]]
6360- [[TGroupBox]]
6461
6562---
6663*From the Free Pascal wiki, page "TCheckGroup", as it stood on 2022-03-08 after a change by Dbannon, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history