tmemo在使用大量线路时很慢。 经验: 我在TMEMO中有100000行。我想做类似的事情: 对于i:= 0 to memo.lines.count-1做 memo.lines [i]:= wayerrim(memo.lines [i]); 但是速度为每秒0.5行!

问题描述 投票:0回答:1
for i:= 0 to Memo.Lines.Count-1 do Memo.Lines[i]:= SomeTrim(Memo.Lines[i]);

但速度为每秒0.5行!!

添加beginupdate/endupdate后,我看不到任何速度提高。
 Memo.Lines.BeginUpdate;
 for i:= 0 to Memo.Lines.Count-1 do
  Memo.Lines[i]:= SomeTrim(Memo.Lines[i]);
 Memo.Lines.EndUpdate;

我的问题是为什么beginupdate/endupdate无济于事?

TStrings.BeginUpdate/EndUpdate
只会禁止

OnChanging

delphi delphi-xe7
1个回答
16
投票
事件。它对内容本身的更改的内部处理没有影响。

TMemo.Lines
TMemoStrings
实现,将文本内容存储在窗口控制本身中。因此,这里是毫无用处的。
您可能通过使用本地
BeginUpdate/EndUpdate

实例获得更好的结果,并使用

TStringList

属性将数据从
Text
TMemo
和返回复制。 
TStringList

属性是一次访问a的整个内容的最有效方法。

Text

注:
在复制内容和备忘录的内容时,请提及使用
TMemo
而不是the the the the the the the the:
  lst := TStringList.Create;
  try
    lst.Text := Memo1.Lines.Text;
    for I := 0 to lst.Count - 1 do begin
      lst[I] := SomeTrim(lst[I]);
    end;
    Memo1.Lines.Text := lst.Text;
  finally
    lst.Free;
  end;
在这种情况下,由于
Assign
属性的内部优化,在这种情况下较慢。此属性的Getter和Setter使用单个WM_GETTEXT/WM_SETTEXT消息直接访问Windows控件,而
Text
使用每行EM_GETLINE消息进行读取以及EM_LineIndex,EM_Setsel,em_linelelength和em_replace em_replace的序列。一个简单的计时测试表明,上面的代码需要大约600毫秒,而用

Assign
呼叫更换
Text

作业则需要超过11秒!

    
测试和结果:
TMemoLines
,uwe是对的。
    
	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.