как узнать что выделено 4 CheckBox

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Leon2009, 7 Jun 2010.

  1. Leon2009

    Leon2009 New Member

    Joined:
    1 Sep 2009
    Messages:
    44
    Likes Received:
    0
    Reputations:
    0
    Здравствуйте! можно ли узнать? у меня на форме 30 CheckBox если из них выделить любые 4 как сделать чтобы хоть сообщение выдал что выделено 4 чекса? спасибо!
     
  2. sn0w

    sn0w Статус пользователя:

    Joined:
    26 Jul 2005
    Messages:
    1,032
    Likes Received:
    1,320
    Reputations:
    327
    переменную сделай++--

    зы чтоб OnClick одинаковый обработчик у всех был

    ззы вы меня паражаите)
     
    1 person likes this.
  3. Leon2009

    Leon2009 New Member

    Joined:
    1 Sep 2009
    Messages:
    44
    Likes Received:
    0
    Reputations:
    0
    наверное так

    Code:
    var i:integer;
    begin
    i:=0;
    if CheckBox1.Checked= true then i:=i+1;
    if CheckBox2.Checked= true then i:=i+1;
    if CheckBox3.Checked= true then i:=i+1;
    if CheckBox4.Checked= true then i:=i+1;
    if CheckBox5.Checked= true then i:=i+1;
    if CheckBox6.Checked= true then i:=i+1;
    label1.Caption:=inttostr(i);
    if i>=3 then label2.Caption:='bolshe ili ravno 3';
    спасибо!
    а если 1000 чексов? :confused:
    т.е одинаковый обработчик?
     
  4. diznt

    diznt Elder - Старейшина

    Joined:
    31 Jan 2008
    Messages:
    432
    Likes Received:
    164
    Reputations:
    -19
    Code:
    var
     i, i2: integer;
    begin
     i2:=0;
    
     for i:=1 to 8 do
      begin
        if TCheckBox(FindComponent('CheckBox'+inttostr(i))).Checked=true then
         inc(i2);
      end;
    
     if i2 = 4 then ShowMessage('Выделенно 4 чекбокса');
    end;
     
  5. Meecript_

    Meecript_ Banned

    Joined:
    29 Oct 2008
    Messages:
    194
    Likes Received:
    62
    Reputations:
    32
    Пример на билдере
    обработчик OnClick всех чекбоксов:
    PHP:
    void __fastcall TMainForm::CheckBoxClick(TObject *Sender)
    {
        
    pCheckBox static_cast<TCheckBox *>(Sender);
        if(
    pCheckBox->Checked)
            
    Label1->Caption IntToStr(++iCBCount);
        else
            
    Label1->Caption IntToStr(--iCBCount);
    }