?
Solved

CheckBox

Posted on 2001-06-29
12
Medium Priority
?
341 Views
Last Modified: 2010-04-06
How can i check whether they checked or not for about 200 checkboxes?
0
Comment
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
  • Learn & ask questions
  • 4
  • 4
  • 3
  • +1
12 Comments
 
LVL 6

Expert Comment

by:Jaymol
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

by:jsweby
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

by:edey
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:systemop
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

by:Jaymol
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

by:jsweby
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

by:systemop
ID: 6238355
Can you explain with an example jsweby?
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6238364
Systemop, what are you attempting to achieve?
0
 
LVL 4

Expert Comment

by:jsweby
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

by:systemop
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

by:
jsweby earned 75 total points
ID: 6238387
Ok, instead then:

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

by:Jaymol
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question