Forum > LCL

Autocomplete in text field with large amount of items

(1/1)

fr.luca:
Hello,
I'm writing a form for anagraphical data entry, and I would like city of birth & residence fields to autocomplete. The list of items to deal with is quite large, i.e. the 8000 cities of my country (Italy).
Firstly I tried to work it out using a combobox, populated at runtime with the query result from a proper db (see hereunder the code).
In order to make the application as portable as it may, and having to deal with both Windows and Linux clients, I had to notice a very different performance, in terms of time response, between the two environments, on machines with similar capabilities.
On Windows, the population of the item list took about 2 seconds, which is a long but reasonable time for my need; on Linux, the duration of the same operation increases 10 times, forcing OS to send a signal about task not responding.
Actually, it's not necessary for me to use a combobox, which control I choose only because of native autocomplete feature.
Any suggestions? Thank you.

  if openDB('codfisc.db')
  then
  begin
     combo.Clear;
     try
       dbquery.SQL.Text:= 'SELECT DESCR FROM COMUNI ORDER BY DESCR';
       dbquery.Open;
       while not dbquery.EOF do
       begin
         combo.Items.Add(dbquery.FieldByName('DESCR').AsString);
         dbquery.Next;
       end;
     finally
        closeDB;
     end;
  end;

paweld:
Use BeginUpdate - should significantly speed up the addition of data to the ComboBox. eg.
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if openDB('codfisc.db') then  begin    combo.Items.BeginUpdate;    combo.Clear;    try      dbquery.SQL.Text := 'SELECT DESCR FROM COMUNI ORDER BY DESCR';      dbquery.Open;      while not dbquery.EOF do      begin        combo.Items.Add(dbquery.FieldByName('DESCR').AsString);        dbquery.Next;      end;    finally      closeDB;    end;    combo.Items.EndUpdate;  end;   

fr.luca:
Thank you for the hint!
unfortunately, on linux time response remains the same order.
Perhaps  the combobox are not intended to work with similar amount of data, maybe I should have to seek for some external tool...

dseligo:

--- Quote from: fr.luca on February 18, 2024, 05:08:51 pm ---Thank you for the hint!
unfortunately, on linux time response remains the same order.
Perhaps  the combobox are not intended to work with similar amount of data, maybe I should have to seek for some external tool...

--- End quote ---

Try to put data in TStringList instead of combobox, just for test. Maybe the problem is in database and not in combobox.

fr.luca:
So, I followed your suggestion: a stringlist is now filled up when the form is created, then combo picks it up at showtime.
The form takes some time before appearing, but that's ok.
By the way,  I tried to use a text file instead of  the former sqlite db, to store the list to be retrieved. Nothing significant occurred.
I suppose there should be some kind of tuning in file accessing and management, but I know nothing about the matter.
Anyway, thank you a lot, now it works decently!

 

Navigation

[0] Message Index

Go to full version