快速搜索Tmemo行的方法
我的表单上有一个 TMemo,允许用户输入项目列表。人们可以在这里输入许多项目。当他们单击“保存”时,会检查 TMemo 的内容,然后将其添加到数据库中。
我在 TStringList 中有第二个列表,我循环检查它的任何项目是否包含在 TMemo 中。
简而言之,它看起来像这样
....
//slItems = TStringList
//mItems = TMemo
for i := slItems.Count -1 downto 0 do
begin
if mItems.Lines.IndexOf(slItems[i]) = -1 then
slItems[i].Delete;
end;
----
所以 stringlist 循环,检查它是否存在于备忘录中,如果不存在从列表中删除。
然而,当有 200 多个项目时,速度开始减慢很多,而当项目超过 1000 时,情况会变得非常糟糕。
搜索 TMemo 最快的方法是什么?
I have a TMemo on a form which allows users to enter a list of items. People can enter many items here. When they click Save the contents of the TMemo is checked and then added to the database.
I have a second list in a TStringList which I loop over and check to see if any of it's items are contained in the TMemo.
In a nut shell it looks like this
....
//slItems = TStringList
//mItems = TMemo
for i := slItems.Count -1 downto 0 do
begin
if mItems.Lines.IndexOf(slItems[i]) = -1 then
slItems[i].Delete;
end;
----
So stringlist looped, check to see if it exists in memo, if not delete from list.
However, with 200+ items this is starting to slow down a lot, and with 1000 it gets real bad.
Whats the fastest way to search a TMemo?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将所有
TMemo
读入本地TStringList
并从中进行工作。每次访问TMemo.Lines
时,您都依赖 Windows 消息传递来与 Windows 提供的多行文本框进行对话。除了高效之外什么都没有!Read all of
TMemo
into a localTStringList
and work from that. Every time you're accessingTMemo.Lines
you're relying on Windows messaging to talk to the windows-provided multi line text box. Anything but efficient!