procedure TfrmBorrow.SpeedButton1Click(Sender: TObject);
var
  SQLStr,SQLAll,Log:String;
  SQLTemp:Pchar;
  arrstr:array[1..5]of String;
  i,l:integer;
  function getsth(CurrEdit:TEdit):boolean;
  begin
    result:=false;
    if CurrEdit.Text<>'' then
      result:=true;
  end;
begin  SQLAll:='';
  SQLStr:='SELECT * FROM "BorrowRecord.db" WHERE ';
  if RadioGroup1.ItemIndex=1 then Log:='OR' else Log:='AND';  if Getsth(Edit_UniNo) then
  arrstr[1]:='(UniNo='''+Edit_UniNo.Text+''')';
  if Getsth(Edit_BorrNo) then
    arrstr[2]:='(BorrowerNo='''+Edit_BorrNo.Text+''')';
  if Getsth(Edit_DateOut) then
    arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')'; 
  if Getsth(Edit_DateIn) then
    arrstr[4]:='(ReturnData='''+Edit_DateIn.Text+''')';
  arrstr[5]:='';
  for i:=1 to 4 do
  begin
    arrstr[5]:=arrstr[5]+arrstr[i];
    if arrstr[i]<>'' then
      SQLAll:=SQLAll+Log+arrstr[i];  end;
  if arrstr[5]='' then
  begin
    showmessage('没有查询项目?');
    exit;
  end;  l:=strlen(Pchar(SQLAll));
  GetMem(SQLTemp,l);
  SQLTemp^ := Chr(0);  if SQLAll[1]='O' then
    StrCat(SQLTemp,Pchar(SQLAll)+2);
  if SQLAll[1]='A' then
    StrCat(SQLTemp,Pchar(SQLAll)+3);  SQLStr:=SQLStr+SQLTemp;  
  FreeMem(SQLTemp);
//  Application.MessageBox(Pchar(SQLStr),'预查询的SQL语句',MB_OK);
//-----------------运行到此,SQL语句是什么样的。贴出来看看。  with QueryBorrRec do
  begin
    SQL.Clear;
    SQL.Add(SQLStr);
    Prepare;
    ExecSQL;
    Open;
 if (queryBorrRec.RecordCount<>1) then
     showmessage('没有你要查找的记录,请重新输入!');
  end;
end;

解决方案 »

  1.   

    if Getsth(Edit_DateOut) then
        arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')'; 
    可能有问题
    改为
    if Getsth(Edit_DateOut) then
        arrstr[3]:='(BorrowData=+Edit_DateOut.Text+)'; 
    试一试
      

  2.   

    if Getsth(Edit_DateOut) then
        arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')'; 
    可能有问题
    改为
    if Getsth(Edit_DateOut) then
        arrstr[3]:='(BorrowData=+Edit_DateOut.Text+)'; 
    试一试
      

  3.   

    你的数据库里面的类型是 Date
    而在程序里面borrowdate and returndate都是string
    类型肯定不匹配的
    datetostr
      

  4.   

    不好意思,刚才浏览器出了问题,Edit_DateOut.Text前后的+号要去掉,
    我的意思就是日期字段应该不用加引号
      

  5.   

    我想你的  if Getsth(Edit_DateOut) then
        arrstr[3]:='(BorrowData='''+Edit_DateOut.Text+''')'; 
      if Getsth(Edit_DateIn) then
        arrstr[4]:='(ReturnData='''+Edit_DateIn.Text+''')';
    这里可能要改,因为实际上你用的是字符串,建议你把BorrowData和ReturnData
    写为to_char(BorrowData)和to_char(ReturnData)不过你要先看看有没有
    to_char这个函数,
    另外OR和AND肯定有用,用错了,结果多半不一样,
      

  6.   

    //-----------------运行到此,SQL语句是什么样的。贴出来看看。
    这个怎么做啊
      

  7.   

    用里头tochar之后,运行出错,并提示我capility not support!