Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
ListBox.Items.Add is slow and flickers Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
03-Sep-02
Category
VCL-General
Language
Delphi 2.x
Views
70
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

ListBox.Items.Add is slow and flickers

Answer:

Adding a (larger) group of entries to a ListBox is very slow, because after every 
"items.add" call the ListBox is repainted.

There are two ways to overcome this: 

Use the Windows message WM_SETREDRAW (see Win32.hlp for details). The VCL provides 
two methods for this: BeginUpdate and EndUpdate. I would assume that this is faster 
than solve #2. 
Read the strings in a temporary TStringList object. Maybe you already have such a 
list - in this case you should use your existing list. Then use the Assign method 
to transfer the whole list.

Solve 1:
1   
2   procedure TForm1.Button1Click(Sender: TObject);
3   var
4     i: integer;
5   begin
6     ListBox1.Items.BeginUpdate;
7     for i := 1 to maxitems do
8       ListBox1.Items.add(IntToStr(i));
9     ListBox1.Items.EndUpate;
10  end;



Solve 2:
11  
12  procedure TForm1.Button2Click(Sender: TObject);
13  var
14    i: integer;
15    tmp: tstringlist;
16  begin
17    tmp := TStringList.Create;
18    for i := 1 to maxitems do
19      tmp.add(inttostr(i));
20    ListBox1.Items.Assign(tmp);
21    tmp.Free;
22  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC