TAdvSearchEdit: Find out which item is selected

I am trying out the TAdvSearchEdit and I'm constantly refilling it with a backgroudquery on entering text. So my searchlist is not static.
I have filled the Object values of the Searchlist.Items with the IDs of the connected itgems from the database. But now I have to find out on Enter which item has been selected.
In your sourcode I see an ItemIndex, but that value is reset before I can use it.
Where can I get this value? Preferably in an Event of course.

As there was no answer yet to this question, I have put a lot of effort in it to get some result, but I'm beginning to think that what I want is not possible, what would be a shame.
What I do is this:
- I fill the Searchlist with a query to the database in the OnChange event:


procedure TForm1.ZoekParentChange(Sender: TObject);
var
  hv     : TList<Thv>;
  nAantal: Integer;
  nTeller: Integer;
  S      : TSearchListItem;
const
  nMax   : Integer = 8;
begin
  hv := FindItems('naam', ZoekParent.Text, '', 0, nMax + 1);
  if hv <> nil then
  begin
    ZoekParent.SearchList.BeginUpdate;
    Try
      ZoekParent.SearchList.Items.Clear;
      nAantal := hv.Count;
      if nAantal > nMax then nAantal := nMax;
      for nTeller := 0 to nAantal - 1 do
      begin
        ZoekParent.SearchList.Items.Add(hv[nTeller].naam.ValueOrDefault);
        ZoekParent.SearchList.Items[ZoekParent.SearchList.Items.Count - 1].&Object := TObject(hv[nTeller].bedrijvenid);
      end;
      if nAantal < hv.Count then ZoekParent.SearchList.Items.Add('+ + + +');
    Finally
      ZoekParent.SearchList.EndUpdate;
      hv.Free;
    End;
  end;
end;


This fills the searchbox on the fly with new, better results as I type.
When I see the result I want, I click on it with the mouse, or go to it by keyboard and press Enter.
That gives me an Editbox with the desired result as Text. But I don't know which ID in the background was selected.
The result seems to disappear before I can use it.
I hope you can offer me a soution, because the searchmechanism works great like this.

The TAdvSearchEdit was not designed with this usage in mind. The TAdvSearchEdit  will do the filtering for matching items itself and does not expect its item list to be changed behind its back.

As such, as-is, this indeed causes conflicts. It will require us to allocate time to investigate whether this will be technically feasible to extend the component to make this possible, but this is outside the scope of the currently supported feature-set.

Can you perhapt suggest another component to achieve this with?
I don't want to use a data aware component, because these don't work well with the Aurelius or XData query. I tried that, but it does not work well.

Sorry, I cannot think of a direct equivalent.
We are not aware of issues with DB-aware components and Aurelius or XData datasets.
If some issue might persist with this, please report this in the Aurelius & XData forums.

I didn't mean to suggest the data-aware components are not working with e.g. the TAureliusDataset. I just don't want to use it that way.

The only thing missing here for me is the last step. When the list of possibilities shows, there is no event to trigger which item in the list is selected. If is was possible to get the id of the selected row it works for me.
I found out that usig the OnChange, OnKeyUp or OnMouseUp events don't work, because they are only triggered when something changes in the field itself. Not when another item is selected. I tried to save ids in these events, but I always end up with the one on top, because that is the last time these events get triggered.
Everytime there is an update of the Component Pack I scan the list to see if something changed here. It's really frustrating that I'm so close, but not able to use the component. Still hoping you will extend it a little further.

You can get the index of the selected item in the dropdown list via:


AdvsearchEdit.SearchList.ItemIndex

Did you try this?
I did. There are two problems that keep me from solving this:
- In the OnDropUp event the SearchList is already empty, so I can't get the id of the chosen item (range check error)
- Before the DropUp occurs I can save the id of the chosen item, BUT there is no event when changing the active item in the searchlist. So when it closes I always get the id of the first item (the only one that is registered in the KeyUp / MouseUp events)

I cannot see that the list would be empty when OnDropUp is happening.

Test code:
procedure TForm1.AdvSearchEdit1DropUp(Sender: TObject; Cancelled: Boolean);
begin
  outputdebugstring(pchar('dropup:'+AdvSearchEdit1.SearchList.ItemIndex.ToString+';'+AdvSearchEdit1.SearchList.Items.Count.ToString));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  AdvSearchEdit1.Items.Add.Captions[0] := 'BMW';
  AdvSearchEdit1.Items.Add.Captions[0] := 'Audi';
  AdvSearchEdit1.Items.Add.Captions[0] := 'Mercedes';
  AdvSearchEdit1.Items.Add.Captions[0] := 'Porsche';
  AdvSearchEdit1.Items.Add.Captions[0] := 'Volkswagen';
end;

From your descriptions, we did already a lot of time consuming guesswork and trial & error. 
I would prefer that you send a sample source project + detailed steps how exactly we can see what you describe. Only then we can efficiently work to try to address your needs.


I have sent you an E-mail by means of the support page with a program that shows the problem.
And an accompanying readme.txt.

We will investigate and report by email.