Solved

CheckBox

Posted on 2001-06-29
12
335 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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

24 Experts available now in Live!

Get 1:1 Help Now