gpt4 book ai didi

Delphi - 清理 TListBox 项目

转载 作者:行者123 更新时间:2023-12-03 18:17:28 26 4
gpt4 key购买 nike

我想通过将列表框与其他两个列表框进行比较来清理列表框。

  • Listbox1 将包含项目的大列表
  • Listbox2 会有我想从 listbox1 中删除的词
  • Listbox3 将包含必须存在的强制性单词才能保留在 listbox1 中

下面是我目前为止得到的代码,它对于大列表来说非常慢。

// not very efficient 
Function checknegative ( instring : String; ListBox : TListBox ) : Boolean;
Var
i : Integer;
Begin
For I := listbox.Items.Count - 1 Downto 0 Do
Begin
If ExistWordInString ( instring, listbox.Items.Strings [i],
[soWholeWord, soDown] ) = True
Then
Begin
result := True; //True if in list, False if not.
break;
End
Else
Begin
result := False;
End;
End;
result:=false;
End;

Function ExistWordInString ( aString, aSearchString : String;
aSearchOptions : TStringSearchOptions ) : Boolean;
Var
Size : Integer;
Begin
Size := Length ( aString );
If SearchBuf ( Pchar ( aString ), Size, 0, 0, aSearchString, aSearchOptions ) <> Nil Then
Begin
result := True;
End
Else
Begin
result := False;
End;
End;

最佳答案

如果您在控件中执行任何与 TStrings 实例循环的操作,那么创建一个临时的 TStringList 实例,将控件项分配给它,然后使用临时列表。

原因是列表框、组合框或类似物中的 Items 属性是通过代理类实现的,该代理类本身不保存字符串,但使用 Windows 消息,如 LB_GETCOUNTLB_GETTEXT 直接从 native Windows 控件检索元素。如果您多次访问一个字符串列表项,那么重复消息处理的开销将加起来。

关于Delphi - 清理 TListBox 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2690698/

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