【发布时间】:2014-03-27 16:23:56
【问题描述】:
这是我在第一个firemonkey出来时第一次遇到的老问题。现在即使使用 XE5 也一样。除非每条新行都添加足够的时间延迟,否则我不能将 TMemo 用于任何事情。
问题出现在具有大量控件的繁重表单上。如果行长到足以被换行并包含特殊字符,那么机会就会增加。如果一个字符串包含换行符,那么它几乎总是会被引发。
在只包含备忘录和填充线程的表单中执行相同操作不会产生任何 AV,我认为其他地方一定有问题。
AV起源于TTextSettings、TTextLayout、TText等
传说
TAgStringList :TStringlist 的派生类,具有日志记录、转换为字节和锁定支持。
FLogMemo : 视觉 TMemo。
FDisplayReq : 将日志行添加到 FLogMemo 的条件。
BeignRead : TMREWSync.BeginRead 的内联方法
EndRead : TMREWync.EndRead 的内联方法
记录方法
procedure TAgStringList.Log
( const APrefixes : Array of String;
const ALogs : Array of String;
const AException : Exception = nil );
var
I : NativeInt;
LogString : String;
begin
LogString := Format ( '[%s]', [FormatDateTime ( 'hh:mm:ss.zzz', Time )] );
for I := 0 to Length ( APrefixes ) - 1 do
LogString := Format ( '%s[%s]', [LogString, APrefixes [I]] );
if Assigned ( AException ) then
LogString := Format ( '%s[%s]', [LogString, AException.ClassName] );
if FDisplayReq then
FLogMemo.Lines.Add ( LogString );
Add ( LogString );
for I := 0 to Length ( ALogs ) - 1 do
begin
if FDisplayReq then
FLogMemo.Lines.Add ( ALogs [I] );
Add ( ALogs [I] );
end;
if Assigned ( AException ) then
begin
if FDisplayReq then
FLogMemo.Lines.Add ( AException.Message );
Add ( AException.Message );
Add ( '' );
end
else
Add ( '' );
end;
日志线程方法
procedure TAgStringList.LogManager;
var
I : NativeInt;
EndIndex : NativeInt;
begin
BeginRead;
EndIndex := GetCount - 1;
if FLogManager.Tag < EndIndex then
begin
if Assigned ( FLogMemo ) then
begin
FLogMemo.BeginUpdate;
for I := FLogManager.Tag to EndIndex do
FLogMemo.Lines.Add ( Strings [I] );
FLogMemo.EndUpdate;
FLogManager.Tag := GetCount;
end;
SaveToFile ( FLogFileName );
end;
EndRead;
end;
【问题讨论】:
标签: multithreading delphi logging firemonkey delphi-xe5