Solved

CheckBox

Posted on 2001-06-29
12
336 Views
Last Modified: 2010-04-06
How can i check whether they checked or not for about 200 checkboxes?
0
Comment
Question by:systemop
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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 25 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi procedure  - Unsatisfied forward or external declaration. 2 160
delphi exception 7 64
Delphi XE10, MySQL Query 4 143
Delphi and Access based Enumeration 9 61
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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