Forum > General

checkbox number

(1/3) > >>

clemmi:
I have about 50 checkBoxes. How can I get the number of the checkbox checked? During runtime of course.
For instance, if CheckBox5 in checked.
Can I get a variable to store the number 5 when the checkbox is checked, so I can use it in the program?
I don't need to know which one is checked, I need the number in a variable when the checkbox is checked.
Thanks!
-cl
 

BigChimp:
So have you searched the wiki and forum for those keywords?

Using a search engine to search for getcontrolindex and Lazarus leads e.g. here
http://lazarus-ccr.sourceforge.net/docs/lcl/controls/twincontrol.getcontrolindex.html

Otherwise you could search for "enumerating controls" or "iterating through controls" or something similar...

edit... and you find posts like
http://forum.lazarus.freepascal.org/index.php/topic,20236.msg116561.html#msg116561
which may be helpful...

clemmi:
thanks for the answer but it didn't help.
I removed those trials words since it may not be what I need.
-cl

BigChimp:

--- Quote from: clemmi on August 02, 2014, 04:40:50 pm ---thanks for the answer but it didn't help.
I removed those trials words since it may not be what I need.

--- End quote ---
Sorry, no idea what "removing those trials words" means. Did you see the link to the forum post I posted? It iterates through some controls:

--- Code: ---var i: Integer;
begin
  for i:=0 to TabSheet1.ControlCount-1 do
    if TabSheet1.Controls[i] is TEdit then ... ;

--- End code ---
... well, you're probably not looking at a tabsheet but a form and you're looking for a radio button not a Tedit, so try something like

--- Code: ---var i: Integer;
begin
  for i:=0 to Self.ControlCount-1 do
    if Self.Controls[i] is TRadiobutton then ...
... something with Self.Controls[i].ControlName or something or perhaps .Name... this is air code...

--- End code ---
Note: I made this code up. Don't know if using Self for the form reference is what should be done here.
No idea if TRadioButton if the correct name, but Lazarus provides autocomplete so you should be able to figure out what to use...

Blaazen:
The most straightforward way to work with 50 checkboxes is to use TCheckGroup or TCheckListBox.

Navigation

[0] Message Index

[#] Next page

Go to full version