如图所示
想利用复选框来进行复杂搜索.我以前用vb实现过,在delphi里语法有些区别,看看哪错了
点击复选框代码如下
procedure TF_jhcx.CheckBox1Click(Sender: TObject);
begin
if checkbox1.Checked=true then
begin
DateTimePicker1.Enabled:=true;
DateTimePicker2.Enabled:=true;
end
else
begin
DateTimePicker1.Enabled:=false;
DateTimePicker2.Enabled:=false;
end;
end;
其它三个复选框一样
点击查询按钮代码如下(这里有错)
procedure TF_jhcx.SpeedButton7Click(Sender: TObject);
var
rktime,rkunits,rkjsr,rkcode:string;
begin         If checkbox1.Checked=true then
        rktime = " billdate>=datetimepicker1.Date and billdate<=datetimepicker2.Date";
    Else
        rktime = "billdate like '%'";
    End If          If checkbox2.Checked=true then
        rkunits = "units like edit3.text";
    Else
        rkunits = "units like '%'";
    End If      If checkbox3.Checked=true then
        rkjsr = "handle like edit4.text";
    Else
        rkjsr = "handle like '%'";
    End If     If checkbox4.Checked=true then
        rkcode = "tradecode like edit2.text";
    Else
        rkcode = "tradecode like '%'";
    End If
    
        SQLTJ = " where " & rktime & " and " & rkunits & " and " & rkjsr & " and " & rkcode & "";
 with adoquery2 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('Select * from tb_warehouse_detailed " & SQLTJ & " order by billdate asc');     //排序
    Open;
  end;end;
报错图如下

解决方案 »

  1.   

    1:if checkbox1.Checked  then 
    2:rktime = ' billdate >=datetimepicker1.Date and billdate <=datetimepicker2.Date'; 
    3:     If checkbox1.Checked=true then 
            rktime = " billdate >=datetimepicker1.Date and billdate <=datetimepicker2.Date"   //; 没有
        Else 
            rktime = "billdate like  '% '"; 
        //End If 没有
    4: SQLTJ = ' where '''+ rktime +''' and '''+ rkunits+''' ************** '; 
    5: with adoquery2 do 
      begin 
        Close; 
        SQL.Clear; 
        SQL.Add( 'Select * from tb_warehouse_detailed " & SQLTJ & " order by billdate asc ');     //排序 
        Open; 
      end; //SQL.Add( 'Select * from tb_warehouse_detailed '''+SQLTJ+''' order by billdate asc ');     //排序 
      

  2.   

    procedure TF_jhcx.SpeedButton7Click(Sender: TObject);
    var
    rktime,rkunits,rkjsr,rkcode,SQLTJ:string;
    begin        If checkbox1.Checked=true then  
            rktime:=' billdate  >=datetimepicker1.Date and billdate  <=datetimepicker2.Date '
        Else
            rktime:= 'billdate like ''';
              If checkbox2.Checked=true then
            rkunits:= 'units like edit3.text'
        Else
            rkunits:= 'units like  ''';
          If checkbox3.Checked=true then
            rkjsr:= 'handle like edit4.text'
        Else
            rkjsr:= 'handle like ''';
         If checkbox4.Checked=true then
            rkcode:= 'tradecode like edit2.text'
        Else
            rkcode:= 'tradecode like ''';        SQLTJ:= ' where '''+ rktime + ''' and '''+ rkunits + ''' and '''+ rkjsr + ''' and '''+ rkcode + '''' with adoquery2 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Select * from tb_warehouse_detailed '''+SQLTJ+ ''' order by billdate asc');     //排序
        Open;
      end;
     end;
    按你的意思我改成这样了才是报错呀报错如下
    [Error] Fjhcx.pas(233): Missing operator or semicolon
    [Error] Fjhcx.pas(239): Incompatible types: 'String' and 'procedure, untyped pointer or untyped parameter'
    [Fatal Error] Fjhpz.pas(73): Could not compile used unit 'Fjhcx.pas'
    还有办法吗,看看哪错了呀
      

  3.   

    樓主的數據庫採用的是Sql Server,我建議樓主利用存儲過程實現吧
      

  4.   

    这应该不难吧,只是我初学delphi,也不太懂
      

  5.   

    看了就头大,强烈建议楼主回去看pascal基础
    var s:String;
    Const SQLString:String='Select * from %s where LastName=%s';
    begin
      s:='今天是: '+FormatDateTime('yyyy-MM-dd',now);
      ShowMessage(s);
      s:=Format(SQLString,['Employees',QuotedStr('Davolio')]);
      ShowMessage(s);
    end;
      

  6.   

    var
      strSql: string;
    begin
      strSql := 'select * from tb_warehouse_detailed where 1>0';
      if checkbox1.Checked=true then
        strSql := strSql+' and billdate>='''+FormatDateTime('yyyy-mm-dd',datetimepicker1.Date)+ ''' and '+
                 'billdate<'''+FormatDateTime('yyyy-mm-dd',IncDay(datetimepicker2.Date))+'''';
      if checkbox2.Checked=true then
        strSql := strSql+' and units like '''+edit3.text+'%''';
      ....
      strSql := strSql+' order by billdate asc';
      ...万事开头难,但不要一开头就养成裹脚的毛病。
      

  7.   

    各位,lynmison,你的方法不错,但使用了存储过程吧,存储过程我没建立呀, 也不会建,就没有不使用存储过程的方法吗