gpt4 book ai didi

delphi - 列表框过滤

转载 作者:行者123 更新时间:2023-12-03 15:45:53 25 4
gpt4 key购买 nike

我有一个包含 10,000 个项目和许多重复项目的列表框!我想将其保存到一个没有重复项目的文件中(一个项目而不是所有副本!),我使用这种方式:

Function TMain.List_ExistsIn(ListBox_NAme: TListBox; EParameter: String): Integer;
Var
i: Integer;
Begin
EParameter := LowerCase(EParameter);
Result := -1;
For i:=0 To ListBox_Name.Items.Count - 1 Do
If EParameter = Lowercase(ListBox_Name.Items[i]) Then Begin
Result := i;
Break;
End;
End;

我使用上面的代码来检测现有项目并按照以下步骤保存它:

Procedure TMain.MakeList(ListBox_Name: TListBox; FileName: String); //================
Var
i: Integer;
Temp_ListBox: TListBox;
Begin
Temp_ListBox := TListBox.Create(Main);
With Temp_ListBox Do Begin
Parent := Main;
Clear;
For i:=0 To ListBox_Name.Count - 1 Do
If Main.List_ExistsIn(Temp_ListBox, ListBox_Name.Items[i]) = -1 Then
Items.Add(ListBox_Name.Items[i]);
Items.SaveToFile(FileName);
Free;
End;
End;

但是需要非常非常长的时间才能进行。有没有更好更快的方法?谢谢。

最佳答案

试试这个

procedure TForm1.FormCreate(Sender: TObject);
var
StrList: TStringList;
I: Integer;
begin
StrList := TStringList.Create;
StrList.Sorted := True;
StrList.Duplicates := dupIgnore;
StrList.AddStrings(ListBox1.Items); //Your List Box Items
StrList.SaveToFile('C:\abc.txt');
StrList.Free; //Cleanup
end;

关于delphi - 列表框过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3083489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com