if combobox1.Text<>'全部' then
  begin
    table2.First;
    while not table2.Eof do //在这里为什么进入了死循环???
    begin
      if table2.Locate('btbz',p_btbz,[]) then
      begin
        p_xlh_list.Add(table2.fieldbyname('xlh').asstring);
      end;
      table2.Next;
    end;
end;

解决方案 »

  1.   

    if combobox1.Text<>'全部' then
      begin
        table2.First;
        while not table2.Eof do //在这里为什么进入了死循环???
        begin
          if table2.Locate('btbz',p_btbz,[]) then
          begin
            //
          end;
          table2.Next;
        end;
    end;
      

  2.   

    这样不死循环才怪呢,因为Locate就改变了记录指针!
      

  3.   

    你是想找出Table2表中所有'btbz'字段值为p_btbz的吧,
    table2.open;
    table2.filtered:=false; 
    table2.filter:='btbz='+p_btbz;
    table2.filtered:=True;
      

  4.   

    要是btbz是String型的

    table2.filter:='btbz='''+p_btbz+'''';
      

  5.   

    如果像这样的话用LOCATE是不行的!因为LOCATE始终是找第一条!你可以改成:if combobox1.Text<>'全部' then
      begin
        table2.First;
        while not table2.Eof do 
        begin
          if table2。FieldByName('btbz').AsString ='p_btbz' then  //假设为字符型,其它类型一样判断!
          begin
            //
          end;
          table2.Next;
        end;
    end;