-1
這是我第一次遇到第一個firemonkey時遇到的老問題。現在即使是XE5也是如此。除非每個新行都添加了足夠的時間延遲,否則我不能使用TMemo。在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;
你能舉一個小例子來說明我該怎麼做? –
BeginUpdate和EndUpdate在它們之間有一個'for',並且根據Log Method,總是添加至少2行。該線程每秒也會迭代,因此總是有10-20行。 –
對不起,沒有發現for循環 –