delphi - 如何快速删除列表框中的重复项?

标签 delphi listbox duplicates

我希望从大型 TListBox 中删除重复的项目。为此,我使用了一种经典的简单方法。它可以工作,但需要 19 分钟。我读了很多书,显然我应该使用 TFileStream (?)。但我不知道怎么办。

我的经典方法是这样的:

procedure NoDup(AListBox : TListBox);
var
  i : integer;
begin
  with AListBox do
  for i := Items.Count - 1 downto 0 do
  begin
    if Items.IndexOf(Items[i]) < i then
    Items.Delete(i);
    Application.ProcessMessages;
  end;
end;

如何提高速度?

最佳答案

procedure NoDup(AListBox: TListBox);
var
  lStringList: TStringList;
begin
  lStringList := TStringList.Create;
  try
    lStringList.Duplicates := dupIgnore;
    lStringList.Sorted := true;
    lStringList.Assign(AListBox.Items);
    AListBox.Items.Assign(lStringList);
  finally
    lStringList.free
  end;
end;

关于delphi - 如何快速删除列表框中的重复项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6701538/

相关文章:

java - ConcurrentHashMap 中 String intern 方法的去重

doctrine-orm - Doctrine 2 重复检测

delphi - 在 Delphi 5 中创建面板的精确副本

delphi - Delphi 中的命名/可选参数?

mysql - 如何获取TADOQuery中字段的长度?

windows-phone-7 - 如何在 wp7 中的列表框项目之间插入特定数量的空间?

C# - 无法在 WinForms 的列表框中执行键值对

multithreading - (Delphi 2009) idIRC、MDI 和挂起问题

c# - 当要滚动的项目太多时,Windows 窗体列表框会溢出

mysql - 使用 ON DUPLICATE KEY UPDATE 进行大的自动插入