1

I've got a problem with ComboEdit on Android. I need add item to ComboEdit.Items in OnPopup event, but my item is visible after second shows popup. How refresh Items in OnPopup event?

procedure TForm1.ComboEditPopup(Sender: TObject);
begin
    ComboEdit1.Items.Add('MyItem'); // this item will by visible at next popup
end;

What I want achieve: Items: 'Aaa', 'Bla', 'Ble', 'Dee'. User writes 'Bl'. When he pushes Popup, ComboEdit will show him items: 'Bla', 'Ble' .

My currently code:

ComboEdit : TComboEdit;
Items : TStringList; // around 1000 strings

    procedure TForm1.ComboEdit1Typing(Sender: TObject);
    var 
        i : integer;
    begin
        ComboEdit.BeginUpdate;

        ComboEdit.Items.Clear;
        for i := 0 to Items.Count-1 do
          if AnsiStartsText(ComboEdit.Text,Items[i]) then
            ComboEdit.Items.Add(Items[i]);

        Items.EndUpdate;
    end;
Nieznany
  • 11
  • 2
  • @TomBrunberg, I'm trying to search after entering the first characters. I don't do this in OnTyping becouse it's too slowly. – Nieznany Apr 08 '19 at 16:54
  • Sorry for my English. If the user presses Popup, ComboEdit will show items only which start with ComboEdit.Text. – Nieznany Apr 08 '19 at 18:25
  • The `OnPopup()` event is too late to modify the `Items` list. But you can use `OnTyping()` event to modify the `Items` list according to what user is typing. You will want to have the complete list stored somewhere else, though. That way, when the user pushes popup the list is already filtered. – Tom Brunberg Apr 08 '19 at 18:58
  • I know, but if list has around 1000 items, searching is slow. So, i must do it otherwise. Thank You :) – Nieznany Apr 08 '19 at 19:16
  • I believe you are doing something wrong if you say it is too slow. But then again, without seeing the relevant code of yours, I might be wrong. Traversing an array with 1000 strings and adding some of them to the `ComboEdit` items can not really be so slow. – Tom Brunberg Apr 08 '19 at 19:20
  • I added my code to post. – Nieznany Apr 08 '19 at 19:39
  • That can be improved: Only search the complete list the first time (1 char entered). Only search from the previous result for any subsequent characters. What is the current time for a search? – Tom Brunberg Apr 08 '19 at 19:45
  • Good idea, thanks! Currently search time is around 2s, i'd like max 1s. With you help it's possible. – Nieznany Apr 08 '19 at 19:50
  • check this URL: [https://stackoverflow.com/questions/5465590/auto-append-complete-from-text-file-to-an-edit-box-delphi?answertab=active#tab-top](https://stackoverflow.com/questions/5465590/auto-append-complete-from-text-file-to-an-edit-box-delphi?answertab=active#tab-top) – minias Apr 09 '19 at 09:30

0 Answers0