Solved

# CheckBox

Posted on 2001-06-29
Medium Priority
341 Views
How can i check whether they checked or not for about 200 checkboxes?
0
Question by:systemop
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 4
• 3
• +1

LVL 6

Expert Comment

ID: 6238199
Let's pretend that the checkboxes are called chk1 - chk200

For I:=1 to 200 do
If TCheckBox(FindComponent('chk'+IntToStr(I))).Checked then .......

That's how you do it!

John.
0

LVL 4

Expert Comment

ID: 6238203
Or if all the components on the form are checkboxes:

For i := 0 to ComponentCount - 1 Do
If (Components[i] is TCheckBox) then
If (Components[i] as TCheckBox).Checked then...

J.
0

LVL 6

Expert Comment

ID: 6238238
For so many check boxes one might consider using a different control to help sort them - that's a lot of potential confusion for a user!  Perhaps a treeView with check boxes?

GL
Mike
0

Author Comment

ID: 6238324
Jaymol thanks for your help but how can i define which checkboxes are checked? ex : i want to give a message for every checked boxes?
0

LVL 6

Expert Comment

ID: 6238332
What are you actually asking then?

Sorry, but it seems your not asking how to tell if they're checked, but asking how to handle an amount of them being checked.

John.
0

LVL 4

Expert Comment

ID: 6238340
One thing to do is give them all a unique number in their Tag property, then you could hold a list of all those checkboxes by tag number whose Checked property is True.

J.
0

Author Comment

ID: 6238355
Can you explain with an example jsweby?
0

LVL 6

Expert Comment

ID: 6238364
Systemop, what are you attempting to achieve?
0

LVL 4

Expert Comment

ID: 6238378
procedure Button1Click(Sender: TObject);
var
CheckBoxArray: Array[1..200] Of Integer;
CheckBoxCheckedCount, i: Integer;
begin
CheckBoxCheckedCount := 0;

For i := 0 to ComponentCount - 1 Do
If (Components[i] is TCheckBox) then
If (Components[i] as TCheckBox).Checked then
Begin
inc(CheckBoxCheckedCount);
CheckBoxArray[CheckBoxCheckedCount] := Components[i] as TCheckBox).Tag;
End;
end;

Essentially what this will give you is:

(a) the number of checkboxes ticked in the CheckBoxCheckedCount variable
(b) the tag numbers of those check boxes which are ticked in the CheckBoxArray variable.

This is by no means exhaustive or even robust, just an idea...

J.
0

Author Comment

ID: 6238380
Summary :

I have 200 checkboxes and one button. Every chckbox has different captions. I check 120 of them. (But they re in different order.) OnButton1.Click i want to write all of the checked CheckBoxes.Caption. Ok Now?
0

LVL 4

Accepted Solution

jsweby earned 75 total points
ID: 6238387

procedure Button1Click(Sender: TObject);
begin
For i := 0 to ComponentCount - 1 Do
If (Components[i] is TCheckBox) then
If (Components[i] as TCheckBox).Checked then
Begin
ShowMessage((Components[i] as TCheckBox).Caption);
End;
end;

This will put out a message for each one that is ticked, you may want to output these to a file.

J.
0

LVL 6

Expert Comment

ID: 6238391
It depends on where you want to write it, but this will create a string with the caption of each checked checkbox.

var
TmpI  : Integer;
TmpS  : String;
Begin
TmpS:='';
For TmpI:=1 to 200 do
If TCheckBox(FindComponent('chk'+TmpI)).Checked then begin
If TmpS<>'' then TmpS:=TmpS+#13;
TmpS:=TmpS+TCheckBox(FindComponent('chk'+TmpI)).Caption;
end;
ShowMessage(TmpS);
End;

John.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small printā¦
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have toā¦
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for ā¦
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastrā¦
###### Suggested Courses
Course of the Month14 days, 1 hour left to enroll