var
edits: array of tedit;
checks: array of tcheckbox;
begin
  setlegnth(edits,10);
  setlegnth(checks,);
  for i:= 0 to 9 do
  begin
    edits[i]:=tedit.create(self);
    checks[i]:=tcheckbox.create(self);
    edits[i].paraent:=form1;
    checks[i].paraent:=form1;
    edits[i].left:=10;
    edits[i].top:= 100+i*20;
    checks[i].left:=100;
    checks[i].top:= 100+i*20;    
  end;
end;最后判断时
作个循环就可以了
注意 edits、checks是公用变量

解决方案 »

  1.   

    你可以定义一string变量str
     if checkbox1.checked=true then
       str :=str+edit1.text;
    ..............query1.close;
    query1.sql.clear;
    query1.sql.add('select * from 表名 where '+str);
    query1.open
      

  2.   

    这需要动态构造SQL,可以根据你的Checked来产生SQL,,
      

  3.   

    补充一下 luoweicaisd(笑三少)的
    str=str+edit1.name+'='+edit1.text+'and ';
    小心循环判断完后要取掉最后的and,另外你还可通过另外一个 checkbox或
    其它控件选择and 还是 or; 是=还是 like!
    可以做模糊查询,
      

  4.   

    edit.enable:=checkbox.enable
    楼上其他的说的也很是明白了
      

  5.   

    为什么要加edit1.name
    另外如何进行>和<查询
      

  6.   

    var 
     str:array[0..4] of string;//全局变量procedure TForm1.CheckBox1Click(Sender: TObject);
    begin
     if checkbox1.checked then 
      str[0]:=edit1.text
      else str[0]:='';
    end;...procedure TForm1.CheckBox5Click(Sender: TObject);
    begin if checkbox5.checked then
      str[4]:=edit5.text
     else str[4]:='';
    end;procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
        strSQL:string;
    begin
     strSQL:='';
     for i:=0 to 4 do
     if str[i]<>'' then
      strSQL:=strSQL+str[i]+' and  ';  strSQL:=copy(strSQL,1,length(strSQL)-5);//去最后的‘ and '
      query1.close; 
     query1.sql.clear;
     query1.sql.add('select * from 表名 where '+strSQL);
     query1.open;end;
      

  7.   

    procedure TSearchForm.BbnSearchClick(Sender: TObject);
    var
      txt1,txt2:string;
      i,j:integer;
      b1,b2:boolean;
    begin
      i:=ComboBox1.itemindex;
      j:=ComboBox2.ItemIndex;
      txt1:=trim(Edit1.Text);
      txt2:=trim(Edit2.Text);
      b1:=(ComboBox1.ItemIndex>=0)and (trim(Txt1)<>'');
      b2:=(ComboBox2.ItemIndex>=0)and (trim(Txt2)<>'');
      if not (b1 or b2) then                  //两个全不满足要求
      begin
        if MessageDlg('您没有输入搜索条件,或者搜索条件有问题,不能进行搜索,还需要搜索吗?',
           mtConfirmation, [mbYes, mbNo], 0)=mrNo then
          SearchForm.Close;
      end
        else
        begin
          DM.QueryBook.Close;
          DM.QueryBook.SQL.Clear;
          SqlTxt:='Select * from DataBook where ';
          if b1 and b2 then
          begin
            if Cbx1.Enabled and Cbx1.Checked then
              SqlTxt:=SqlTxt+cbbToPro(i)+' like ''%'+Txt1+'%'''
              else
                 SqlTxt:=SqlTxt+cbbToPro(i)+' = '''+Txt1+'''';
            if Cbx2.Enabled and Cbx2.Checked then
               SqlTxt:=Sqltxt+' and '+cbbToPro(j)+' like ''%'+Txt2+'%'''
               else
                 SqlTxt:=Sqltxt+' and '+cbbToPro(j)+' = '''+Txt2+'''';
          end;      if (not b1) and b2 then
          begin
            if Cbx2.Enabled and Cbx2.Checked then
               SqlTxt:=Sqltxt+cbbToPro(j)+' like ''%'+Txt2+'%'''
               else
                 SqlTxt:=Sqltxt+cbbToPro(j)+' = '''+Txt2+''''
          end;
          if b1 and (not b2) then
          begin
            if Cbx1.Enabled and Cbx1.Checked then
              SqlTxt:=SqlTxt+cbbToPro(i)+' like ''%'+Txt1+'%'''
              else  SqlTxt:=SqlTxt+cbbToPro(i)+' = '''+Txt1+''''
          end;
          DM.QueryBook.SQL.Add(SqlTxt);
      //    DM.QueryBook.Prepare;
          DM.QueryBook.Open;  // LblUp.Caption:=Format('符合条件的图书有%d本。',[DM.QueryBook.RecordCount]);
       StatusBar1.Panels[0].Text:=Format('符合条件的图书有%d本。',[DM.QueryBook.RecordCount]);
       StatusBar1.Panels[1].Text:='单击图书可查看图书信息。';
      //   DM.QueryBook.Fields.   end;
    end;
    //这是我毕业设计里的一段代码。功能是:用两个combobox来查询。当然,也可以只用一个Combobox来查询。希望能对有所作用。
      

  8.   

    function tfqryfeewhere.getwhere:tstrings;
    var
      s:tstrings;
      priceid:string;
    begin
    s:=tstringlist.Create;
    s.Clear;
    s.add('select * from fee,yh where (fee.Yh_ID=yh.Yh_ID)');
    if chkyhid.Checked then
      begin
        s.Add(' and (fee.Yh_ID='+edtyhid.Text+')');
      end;//if chkyhid.Checked then
    if chkyhname.Checked then
      begin
        s.Add(' and (fee.Yh_Name='''+edtyhname.Text+''')');
      end;
    if chkmonth.Checked then
      begin
        s.Add(get_month_where);
      end;
    if chkfeedate.Checked then
      begin
       s.Add(' and (fee.Pay_Date>'+datetimetostr(dtppaystart.Datetime)+')');
       s.Add(' and (fee.Pay_Date<'+datetimetostr(dtppayend.Datetime)+')');
      end;
    if chksupp.Checked then
      begin
        s.Add(' and (fee.Pay_Acroom='''+edtsupp.Text+''')');
      end;
    if chkreceiver.Checked then
      begin
        s.Add(' and (fee.Pay_Acman='''+edtreceiver.Text+''')');
      end;
    if chkpayment.Checked then
      begin
        if rdopay.Checked then
          begin
            s.Add(' and (fee.Pay_Is=1)');
          end
          else begin
            s.Add(' and (fee.Pay_Is=0)');
          end;
      end;
    if chkydtype.Checked then
      begin
        s.Add(' and (yh.Yd_Type='''+cmbydtype.Text+''')');
      end;
    if chkprice.Checked then
      begin
        dm.Tprice.Locate('Price_Title',cmbprice.Text,[]);
        priceid:=dm.Tprice.fieldbyname('Price_ID').asstring;
        s.Add(' and (yh.Price_ID='+priceid+')');
      end;
    if chkammid.Checked then
      begin
        s.Add(' and (yh.Amm_ID='''+edtammid.Text+''')');
      end;
    if chktranid.Checked then
      begin
        s.Add(' and (yh.Tran_ID='+cmbtranid.Text+')');
      end;
    result:=s;
    end;
    procedure TFQryfee.btnQClick(Sender: TObject);
    beginapplication.CreateForm(tfqryfeewhere,fqryfeewhere);
    if fqryfeewhere.ShowModal=mrok then
      begin
        dm.Qfee.Close;
        dm.Qfee.SQL.Clear;
        dm.Qfee.SQL.AddStrings(fqryfeewhere.getwhere);
        dm.Qfee.Open;
      end;
    fqryfeewhere.free;
    end;
      

  9.   

    OnCheckBoxClick事件中加:  CheckBox.Checked:=Edit.Visible( or Enabled )
      

  10.   

    //昨天写漏了一些var 
     str:array[0..4] of string;//全局变量procedure TForm1.CheckBox1Click(Sender: TObject);
    begin
     if checkbox1.checked then 
      str[0]:='字段名0 ='+ edit1.text//模糊查询str[0]:='字段名0 like '
      else str[0]:='';
    end;...procedure TForm1.CheckBox5Click(Sender: TObject);
    begin if checkbox5.checked then
      str[4]:='字段名4='+ edit5.text
     else str[4]:='';
    end;procedure TForm1.Button1Click(Sender: TObject);
    var i:integer;
        strSQL:string;
    begin
     strSQL:='';
     for i:=0 to 4 do
     if str[i]<>'' then
      strSQL:=strSQL+str[i]+' and  ';  strSQL:=copy(strSQL,1,length(strSQL)-5);//去最后的‘ and '
      query1.close; 
     query1.sql.clear;
     query1.sql.add('select * from 表名 where '+strSQL);
     query1.open;end;