Why doesn't THashedStringList ignore duplicates?

白昼怎懂夜的黑 提交于 2020-01-14 08:09:31

问题


I have the following code:

var
  sl: THashedStringList;
begin
  sl:= THashedStringList.Create;
  sl.Duplicates := dupIgnore;
  sl.Add('12345');
  sl.Add('12345');
  sl.Add('12345');
  sl.Add('12345');
  sl.Add('12345');
  sl.Add('12345');
  sl.Add('12345');
  ShowMessage(IntToSTr(sl.Count));
end;

But when I see sl.Count, it gives me 7. What is the bug in this?


回答1:


You need to set the Sorted property to TRUE in order to have the list ignore duplicates. The property is inherited from TStringList, and if you look at the documentation for TStringList.Duplicates you will find:

Note: Duplicates does nothing if the list is not sorted.



来源:https://stackoverflow.com/questions/1064446/why-doesnt-thashedstringlist-ignore-duplicates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!