How can I remove duplicate items from ListBox in Delphi? I know this:
for i := ListBox1.Items.Count-1 downto 1 do
for j := 0 to i-1 do
if ListBox1.Items[i] = ListBox1.Items[j] then
ListBox1.Items.Delete[i];
But I need to remove duplicates only if first 10 letters are the same, so I have tried this:
for i := ListBox1.Items.Count-1 downto 1 do
for j := 0 to i-1 do
if copy(ListBox1.Items[i],1,11) = copy(ListBox1.Items[j],1,11) then
ListBox1.Items.Delete[i];
But when I try to remove duplicates, I get list out of bonds error 🙁
You need to add a
breakafter theDelete:(Indeed, if you
Deletethe item with indexi, then how can you make the comparisonif Copy(ListBox1.Items[i], 1, 10) = ...the next time?)