这个是以前站长的一个程序中的代码,你参考一下: procedure Tfrm_YQ_Lab.SpeedButton1Click(Sender: TObject); var SQLStr,SQLAll,Log:String; SQLTemp:Pchar; arrstr:array[1..7]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 "仪器库.db" WHERE '; if RadioGroup1.ItemIndex=1 then Log:='OR' else Log:='AND'; if Getsth(Edit_name) then arrstr[1]:='(仪器名称=''+Edit_name.Text+'')'; arrstr[2]:=ComboBox1.text; if arrstr[2]<>' then arrstr[2]:='(状况=''+arrstr[2]+'')'; if Getsth(Edit_No) then arrstr[3]:='(型号=''+Edit_No.Text+'')'; if Getsth(Edit_date) then arrstr[4]:='(启用日期=''+Edit_date.Text+'')'; if GetSth(Edit_address) then arrstr[5]:='(放置位置=''+Edit_address.Text+'')'; if GetSth(Edit_experi) then arrstr[6]:='(所属实验=''+Edit_experi.Text+'')'; arrstr[7]:='; for i:=1 to 6 do begin arrstr[7]:=arrstr[7]+arrstr[i]; if arrstr[i]<>' then SQLAll:=SQLAll+Log+arrstr[i]; end; if arrstr[7]=' then begin showmessage('没有查询项目?'); exit; end;