with frmdm.qryrep do
begin
  first;
  while not eof do
  begin
    cbxCommu.Items.Add(fieldvalues['Community']);
    next;
  end;
end;

解决方案 »

  1.   

    while not frmdm.qryrep.eof do
    begin
      CbxCommu.Items.Add(frmdm.qryrep.fieldvalues['Community']);
      frmdm.qryrep.next;
    end;
      

  2.   

    楼上说的对,不要用for循环,用while do结构。你有可能不知道究竟有多少记录,另外query查询后,用first;next;移动当前指针,直到最后跳出循环。
      

  3.   

    最好在add前先ComboBox.Items.Clear
      

  4.   

    首先sql语句要写正确!其次是用combobox前,先清除以前的东西!
    var
      sSql, sValue: string;
    begin
      combobox1.clear;
      sSql := 'select distinct Community from table1';
      //问题可能出在这里'distinct'
      Query1.close;
      Query1.Sql.clear;
      Query1.Sql.add(sSql);
      Query1.open;
      Query1.first;//移动到数据集的最前;
      while not Query.eof do
      begin
        sValue := Query1.fieldbyValues['Community'];
        combobox1.items.add(sValue);
      end;  
    end;
      

  5.   

    首先sql语句要写正确!其次是用combobox前,先清除以前的东西!
    var
      sSql, sValue: string;
    begin
      combobox1.clear;
      sSql := 'select distinct Community from table1';
      //问题可能出在这里'distinct'
      Query1.close;
      Query1.Sql.clear;
      Query1.Sql.add(sSql);
      Query1.open;
      Query1.first;//移动到数据集的最前;
      while not Query.eof do
      begin
        sValue := Query1.fieldbyValues['Community'];
        combobox1.items.add(sValue);
      end;  
    end;
      

  6.   

    楼上的请注意:
    我是谁写的代码是一个死循环,除非query没有记录,不然就死在循环中了。
      

  7.   

    对啊,while do循环中少了最后一句话Query1.Next;