Re: Populating a combo from a database table faster
- From: "Chris" <nospam@xxxxxxxxxx>
- Date: Thu, 30 Mar 2006 11:23:34 +0100
<tglunz@xxxxxxxxxxxxxxxxxxxxx> wrote in message
news:442aef09$1@xxxxxxxxxxxxxxxxxxxxxxxxx
Good afternoon,
I was wondering if anyone know a faster way to populate a combo? In some
cases these combos maybe populated from a query which may return 20,000
records. I am not a fan of populating a combo with that many records, but
it is not my choice. The following code take 7 second to populate the
combo
with 20,000 values:
Combo.items.clear;
CodeQuery.First; // ADO dataset
while CodeQuery.Eof = False do
begin
Combo.Items.Add(CodeQuery.Fields[0].AsString);
CodeQuery.Next;
end;
Hi
Try this
//----------------------------------------------------------------------
var
o : Variant;
i : Integer;
c : integer;
begin
Combo.items.clear;
CodeQuery.First; // ADO dataset
//Add ADOInt to get the defines
o := CodeQuery.Recordset.GetRows(adGetRowsRest, adBookmarkCurrent,
'UniqueID' );
c := VarArrayHighBound(o,2);
for i := 0 to c do
begin
Combo.Items.Add(VarArrayGet(o,[0,i]));
end;
ShowMessage(IntToStr(combo.Items.Count ));
end;
//------------------------------------------------------------------------------------------
In my tests it took sub 2 seconds to load 12,000+ items compared to about
6seconds with your code.
Please forgive the poor Delphi style, I use BCB normally.
Hope it helps
Chris
.
- References:
- Populating a combo from a database table faster
- From: tglunz
- Populating a combo from a database table faster
- Prev by Date: Re: Visual query builder
- Next by Date: Re: Visual query builder
- Previous by thread: Re: Populating a combo from a database table faster
- Next by thread: ANN: Comments competition going strong...
- Index(es):
Relevant Pages
|