Srdjan Vukmirica
Srdjan Vukmirica

Reputation: 753

How to remove duplicates in ListBox?

I use this code to remove duplicates:

procedure TForm1.RemoveDuplicates(StrList : TStringList);
var   NoDuplicate: TStringList;
      i: Integer;
begin
  NoDuplicate := TStringList.Create;
  try
    NoDuplicate.Sorted := True;
    NoDuplicate.Duplicates := dupIgnore;
    ///
    for i := 0 to StrList.Count - 1 do
    NoDuplicate.Add(StrList[i]) ;
    ///
    NoDuplicate.Sorted:= False;
    StrList.Assign(NoDuplicate) ;
  finally
    NoDuplicate.Free;
  end;
end;  

It works fine. But problem with "dupIgnore" is that it's not case-sensitive. For example, "rodeo" & "Rodeo" for "dupIgnore" are duplicates, although they are not. How to fix this?

Upvotes: 1

Views: 545

Answers (1)

Tim3880
Tim3880

Reputation: 2583

Try

NoDuplicate.CaseSensitive := True;

Upvotes: 7

Related Questions