Results 1 to 6 of 6

Thread: checkbox

  1. #1
    Join Date
    Nov 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default checkbox

    OK so i have about 30 checkboxes in my form and on a button press i want to be able to check which of each check box is check and store a 1 inside if it is check or a 0 if it is not checked inside a 30 integer wide array. I want to do this in a simple loop but i dont know how to loop through each check box. The checkboxes are named cb1,cb2,cb3,cb4...,...cb30.

    Heres my current code:

    PHP Code:
    for icb:= 1 to 30 do
    begin
    if (cb[icb].checkedthen begin
    ItemControlArray
    [icb]:=1;
    end else begin ItemControlArray[icb]:=0;  end;

    end
    This gives me an error cause I just dont know if its possible to loop through the checkboxes cb[1..30] in anyway?

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    What you would do is declare an array like var CheckboxArr : array of TCheckbox; and then you would loop through like this:
    Simba Code:
    h := high(CheckBoxArr);
    for i := 0 to h do
      CheckedArr[i] := Integer(CheckBoxArr[i].Checked);
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Nov 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  4. #4
    Join Date
    Nov 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ok it seems that the array is filled with all zeros even when the checkboxes are ticked. here is my code

    PHP Code:
    var CheckboxArr : array of TCheckbox;
    ItemControlArray : Array[1..80of integer;

    procedure button1Procedure(senderTObject);
    var
    i,h:integer;
    begin


    := high(CheckBoxArr);
    for 
    := 0 to h do
        
    begin
        ItemControlArray
    [i] := Integer(CheckBoxArr[i].Checked);
        
    end;

    //display values in array
    for := 1 to 80 do
    begin
    writeln
    (ItemControlArray[i])  ;
    end;
    end
    edit:looks like h is giving value of -1
    Last edited by IwriteCode; 07-07-2011 at 02:25 PM.

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    It looks like you haven't set the length of the checkbox array. Try putting SetArrayLength(CheckboxArr, 30) above that line.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  6. #6
    Join Date
    Nov 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ah got it working my silly mistake

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •