I am trying to remove duplicates in my listview.
This function:
procedure RemoveDuplicates(const LV:TbsSkinListView);
var
i,j: Integer;
begin
LV.Items.BeginUpdate;
LV.SortType := stText;
try
for i := 0 to LV.Items.Count-1 do
begin
for j:=i+1 to LV.Items.Count-1 do
begin
if SameText(LV.Items[i].SubItems[0], LV.Items[j].SubItems[0]) and
SameText(LV.Items[i].SubItems[1], LV.Items[j].SubItems[1]) and
SameText(LV.Items[i].SubItems[2], LV.Items[j].SubItems[2]) and
SameText(LV.Items[i].SubItems[3], LV.Items[j].SubItems[3]) then
LV.Items.Delete(j);
end;
end;
finally
LV.SortType := stNone;
LV.Items.EndUpdate;
end;
ShowMessage('Deleted');
end;
does not delete the duplicates. What is wrong with it?
At a guess, since you haven’t mentioned what is going wrong, I would think that is has to do with the fact that
iandjare invalid after you have deleted an item because you are counting UP.A better idea would be to count down instead: