Thanks for taking the time to reply, but I don't understand your code. How this could help in my question?
ASerge's code tests whether the item's string (
id?) is already there and, if so, replaces the object. If not, then just adds the item. All you have to do is call
AddToListBox(ListBox1, Id, Buff);Anyway, I came up with a solution, but I'm still not statisfied because it is much slower than it was.
Instead of
I'm using now
ListBox1.Items.Delete(i);
ListBox1.Items.Insert(i,buf2);
It is working but it is slow because Insert calls a windows sort function, which is unnecessary because I insert the new data at the correct place.
When the items are sorted
Insert() behaves like
Add() because it has to keep the list sorted. The only way to avoid it is to make
ListBox.Sorted := False before you perform the operation ... but then you'd have to set it to
True after, which would trigger the sorting.
One thing: you're using Insert and Add, which only treat with the string part of the items: ASerge's solution then won't work for you unless you separate the ID from the rest of the data. The ID then would go to the string and the other data to the object. Otherwise, your own solution is the only one I can think of.