微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

delphi – 为什么THashedStringList不会忽略重复?

我有以下代码
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;

但是当我看到sl.Count时,它给了我7.这是什么错误

解决方法

您需要将Sorted属性设置为TRUE,以使列表忽略重复项.该属性继承自TStringList,如果您查看TStringList.Duplicates的文档,您会发现:

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

原文地址:https://www.jb51.cc/delphi/102064.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐