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?
但是当我看到sl.Count时,它给了我7.这是什么错误?
1 个解决方案
#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:
您需要将Sorted属性设置为TRUE,以使列表忽略重复项。该属性继承自TStringList,如果您查看TStringList.Duplicates的文档,您会发现:
Note: Duplicates does nothing if the list is not sorted.
注意:如果列表未排序,则重复项不执行任何操作。
#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:
您需要将Sorted属性设置为TRUE,以使列表忽略重复项。该属性继承自TStringList,如果您查看TStringList.Duplicates的文档,您会发现:
Note: Duplicates does nothing if the list is not sorted.
注意:如果列表未排序,则重复项不执行任何操作。