combobox下拉列表中的值通过以下方式加入,但如果表中有一万多条记录的话,这样会很慢,还有别的好办法吗?
  qy1.close;
  qy1.SQL.Clear;
  qy1.SQL.Add('select dw from mlb order by sxh');
  qy1.Open;
  combobox1.Items.Clear;
  while not qy1.Eof do
  begin
  combobox1.Items.Add(qy1.fieldbyname('dw').AsString);
  qy1.Next;
  end;

解决方案 »

  1.   

     with ComboBox1.Items do
      try
        BeginUpdate;
        while(...)do Add...
      finally
        EndUpdate;
      end;
    NOTE:不能下條件嗎,比如最近的多少條記錄?用TOP 100...它必竟只能選擇一條,要麼你就用線程
      

  2.   

    可以考虑先写入TStringList,不调用界面控件:
    var
      sL: TStringList;
    begin
      sL:= TStringList.Create;
      qy1.close;
      qy1.SQL.Clear;
      qy1.SQL.Add('select dw from mlb order by sxh');
      qy1.Open;
      while not qy1.Eof do
      begin
        sL.Add(qy1.fieldbyname('dw').AsString);
        qy1.Next;
      end;
      ComboBox1.Clear;
      ComboBox1.Items.AddStrings(sL);
      sL.Free;
    end;
    这样应该能快点。
      

  3.   

    我测试了下,1W多条加载到下拉框里没多久啊··是不是你的SQL取数据耗时太多。
      

  4.   

    这种设计本来就垃圾,想想看,选择的目的就是快捷输入,如果选择还不如手工快的话那不如不选。建议:采用Lookup之类的下拉框,设计成输入敏感,类似于浏览器的输入过滤。做的比较好的就是cxLookup了,Dev的组件。
      当然另外一种做法就是一个Grid列表出来,用户Filter也可以,肯定比一万多个选项下拉要好的多。程序的易用性是门学问,多看看别人做的类似的软件罢
      

  5.   

    我写了个多线程加载的给你看看···我加载了10W条,这样就看出来效率了。
    [code=unit] Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls,Thread;type
      TForm1 = class(TForm)
        ComboBox1: TComboBox;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      I: Integer;
      aThread :MyThread;
    begin    aThread :=MyThread.Create(ComboBox1);
    end;end.
    [/code]
      

  6.   

    多线程单元为unit Thread;interfaceuses
      Classes,StdCtrls,SysUtils,windows,Messages,Forms;type
      MyThread = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      public
        ThreadCombobox :TComboBox;
        constructor Create(AComboBox:TComboBox);
        procedure AddComboItem;
      end;implementation{ Important: Methods and properties of objects in VCL or CLX can only be used
      in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure MyThread.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ MyThread }procedure MyThread.AddComboItem;
    var
      I: Integer;
    begin
        for I := 0 to 100000 - 1 do    // Iterate
        begin
            Application.ProcessMessages;
            ThreadCombobox.Items.Add(IntToStr(I));
        end;    // for
    end;constructor MyThread.Create(AComboBox:TComboBox);
    begin
        inherited Create(false);
        ThreadCombobox := AComboBox;
        self.FreeOnTerminate :=True;
    end;procedure MyThread.Execute;
    begin
      { Place thread code here }
         self.Synchronize(AddComboItem);
    end;end.
      

  7.   

    combobox中添加1万条记录这合理吗?
      

  8.   

    unit1 和thread 同属于一个工程文件···希望对你有所帮助。
      

  9.   

    需要单独建一个多线程单元,然后调用这个多线程吗?在什么地方打开表取值向combobox里添加值?
      

  10.   

    建议如果combobox超过100条数据,就选其它的表现形式了,不然界面不友好了
      

  11.   

    记住加BeginUpdate 和 EndUpdate ,BeginUpdate要放在Clear前面
      

  12.   

    我觉得可以先不用那样,,,,,,
    可以先用一个字符串列表,再冲字符串列表里到导进box里面去。
      list:=Tstringlist.create;
    ......
      qy1.close;
      qy1.SQL.Clear;
      qy1.SQL.Add('select dw from mlb order by sxh');
      qy1.Open;
      combobox1.Items.Clear;
      while not qy1.Eof do
      begin
      combobox1.Items.Add(qy1.fieldbyname('dw').AsString);
      qy1.Next;
      end;