下面的是要執行的內容
   var str:string;
begin
    str:='select * from customertype where tcode='''+trim(cxDBButtonEdit4.text)+'''';
    with dm.qscan02 do
    begin
      close;
      sql.clear;
      sql.add(str);
      open;
    end;
    if dm.qscan02.RecordCount<=0 then
      begin
      showmessage('Type is not exist');      cxDBButtonEdit4.text:='';
      end;
end;
要求該函數可以傳入cxDBButtonEdit4的值和表名稱customertype 和字段名稱tcode
返回的結果為boolen值黨RecordCount<=0時為false >0 時為true

解决方案 »

  1.   

    function www(str:string):boolean ;
    Var
      Data:TAdoQuery;
    begin
      Data:=TadoQuery.Create(nil);
      try
        Try
        Data.Connection:=  //在这赋一个可用的TAdoConnection
          with Data do
          begin
            sql.Text:='select count(*) as count from customertype where tcode='+#39+trim(str)+#39;
            prepared:=true;
            open;
            if fieldbyname('count').AsInteger<1 then
              Result:=false
            else
              Result:=true;
          end;
        Finally
          Data.Free;
        End;
      except
        Data.Free;
        showmessage('出错了!');
      end;
    end;