Solved

CheckBox

Posted on 2001-06-29
12
334 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

by:systemop
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:systemop
Comment Utility
Can you explain with an example jsweby?
0
 
LVL 6

Expert Comment

by:Jaymol
Comment Utility
Systemop, what are you attempting to achieve?
0
 
LVL 4

Expert Comment

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now