procedure GeneralcmbBox(AcmbBox:TComboBox;AstrSQL:string);
begin
   AcmbBox.Clear;
   with TADOQuery.Create do
   begin
     TRY
       if ConnectionString = '' then CoonectionString := ADOCnStr;//Const or public Var
       Close;
       SQL.Text := AstrSQL;
       Open;
       if IsEmpty then Exit;
       while not Eof do
       begin
         AcmbBox.Items.Add(Fields[0].AsString);
         Next;
       end;
       Close;
     FINALLY
       Free;
     END;
   end;
end;

解决方案 »

  1.   

    procedure GeneralcmbBox(AcmbBox:TComboBox;AstrSQL:string);
    begin
       AcmbBox.Clear;
       with TADOQuery.Create do
       begin
         TRY
           if ConnectionString = '' then CoonectionString := ADOCnStr;//Const or public Var
           Close;
           SQL.Text := AstrSQL;
           Open;
           if IsEmpty then Exit;
           while not Eof do
           begin
             AcmbBox.Items.Add(Fields[0].AsString);
             Next;
           end;
           Close;
         FINALLY
           Free;
         END;
       end;
    end;
      

  2.   

    我想用于填充COMBOBOX的字段只要一个,所以不必要知道确定的字段名称(当然使用字段名也可),只需用Fields[0]代替即可。
    另外如果希望该函数的内涵再大点,则只要将ADOQUERY的连接字符串connectionstring作为一个参数就行,其它情况根据需要增改参数即可。
      

  3.   

    可以说详细点吗?是在ComboBox原有记录的基础上再增添新的SQL查询结果记录还是每次只想获得本次查询的记过记录?
    基本思路同楼上的smallbridge