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;
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;
解决方案 »
- 類型轉換問題
- MEMOT中的内容在不断的增加,每次增加都是在上次增加内容基础上换行增加,怎样才能把每次增加的的内容传出来
- c++builder写客户端调用由Java写服务端的WebService问题? 发布到Tomcate中
- 灌灌水,散散分!
- SQLServer数据库服务器名称的获取以及用户表的获取
- WebSnap 之永恒的对勾!!!???
- 谁能告诉我用代码控制光驱的打开和关闭的api
- 请教各位前辈一个关于拨号连接远程数据库的问题,请前辈们不要见笑。
- 哪里有psapi的资料下载啊
- 如何让DBGRID中的内容分页显示
- 如何判定更改的是哪一列
- 求助:delphi2009自定义ip address control时有黑边的问题
try
BeginUpdate;
while(...)do Add...
finally
EndUpdate;
end;
NOTE:不能下條件嗎,比如最近的多少條記錄?用TOP 100...它必竟只能選擇一條,要麼你就用線程
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;
这样应该能快点。
当然另外一种做法就是一个Grid列表出来,用户Filter也可以,肯定比一万多个选项下拉要好的多。程序的易用性是门学问,多看看别人做的类似的软件罢
[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]
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.
可以先用一个字符串列表,再冲字符串列表里到导进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;