Ben*_*eny 4 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;
Run Code Online (Sandbox Code Playgroud)
我怎样才能提高速度?
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;
Run Code Online (Sandbox Code Playgroud)