Efficiently populate combobox in Delphi -


need add many items (more 10k) in tcombobox (i know tcombobox not supposed hold many items not me change this) without adding duplicates. need search full list before adding. want avoid tcombobox.items.indexof need binary search binary find not available in tstrings.

so created temporary tstringlist, set sorted true , used find. assigning temporary tstringlist tcombobox.items

(mycb.items.addstrings(mylist))  

is slow copies whole list. there way move list instead of copying it? or other way efficient populate tcombobox?

as rudy velthuis mentioned in comments , assuming using vcl, cb_initstorage message option:

sendmessage(mycb, cb_initstorage, mylist.count, 20 * mylist.count*sizeof(integer)); 

where 20 average string length.

results (on i5-7200u , 20k items random length betwen 1 , 50 chars):

  • without cb_initstorage: ~ 265ms
  • with cb_initstorage: ~215ms

so while can speed things little preallocating memory, bigger issue seems bad user experience. how can user find right element in combobox such many items?


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -