我希望从大型 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/