1.看看Format的帮助,很强大,肯定能实现你所说的。
2.设个断点调试一下,看赋值后Table1.Filter的内容,会有发现的.

解决方案 »

  1.   

    你是想怎样?
    Format('pos('+'''%s'''+','+'%s'+')>0',[SearchExp,SearchField]); --通吗??
      

  2.   

    to Snakeguo:
    我的字符串是经常变的,是查询表达式,比如姓名以“黄”开头的记录……
    to tongki_8:
    我是想某个字段中包含某字符串的所有记录筛选出来。
      

  3.   

    Table1.Filter :=Format('%s LIKE %s')>0',[SearchField, QuotedStr(SearchExp + '
    %')]);
      

  4.   

    to zswang(伴水)(需要充充电):
    有语法错误呀!麻烦你再帮我看看,谢谢!
      

  5.   

    只能用OnFilterRecordprocedure TForm1.ADOTable1FilterRecord(DataSet: TDataSet;
      var Accept: Boolean);
    begin
      if pos(dataset.FieldByName('cSearchFieldName').AsString,cSearchExp)>0 then//cSearchExp可设置为string型变量
        accept:=true
      else
        accept:=false;
    end;
      

  6.   

    Table1.Filter :=Format('%s LIKE %s>0',[SearchField, QuotedStr(SearchExp + '
    %')]); 
      

  7.   

    to zswang(伴水)(需要充充电):
    编译时提示"Incompatible types"
    to tramplyc(破帽遮颜):
    我的查询条件是经常变动的,不能只接写到OnFilterRecord事件吧!
      

  8.   

    Table1.Filter :=Format('%s LIKE ''%s%%''>0',[SearchField, QuotedStr(SearchExp)]); 
      

  9.   

    to windindance(风之舞):
    编译时提示"Incompatible types: 'String'and 'TEdit'"
    like 可以用在这边吗?
      

  10.   

    你的SearchField和SearchExp是TEdit吗?
    那应该用SearchField.Text和SearchExp.Text
      

  11.   

    对不起,我范一个极严重的错误,程序前面有Exp:=trim(SearchExp.Text);
    SearchExp应该是Exp的,但还是不行,报错“Filter Expression incorrectly teminated"
      

  12.   

    我自己用以下方法解决了,还是谢谢大家!结帐了!!!procedure Thhtx.BtnSearchClick(Sender: TObject);
    begin
       if trim(SearchExp.text)='' then
       Begin
          MessageBox(handle,'查询表达式不能为空,请确认查询表达式是否为空!',
          '提示信息',MB_OK+MB_ICONINFORMATION);
          Exit;
       End;
       try
          Table1.Filtered :=False;
          Table1.OnFilterRecord:=FilterRecord;
       finally
          Table1.Filtered :=True;
       end;
       hhtx.SearchExp.Text :='';
    end;procedure Thhtx.FilterRecord(DataSet: TDataSet; var Accept: Boolean);
    var
       Exp,FieldValue:String;
    begin
       Exp:=trim(SearchExp.Text);
       if RadName.Checked =True then
          FieldValue:=Table1.fieldbyname('姓名').AsString
       else
          if RadNickName.Checked =True then
             FieldValue:=Table1.fieldbyname('昵称').AsString
          else
             FieldValue:=Table1.fieldbyname('编号').AsString;
       if pos(uppercase(Exp),uppercase(FieldValue))<>0 then
          Accept:=true
       else
          Accept:=False;
    end;