- Timestamp:
- Jun 4, 2012, 9:51:41 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UDebugLog.pas
r305 r372 6 6 7 7 uses 8 Classes, SysUtils, FileUtil ;8 Classes, SysUtils, FileUtil, SpecializedList, SyncObjs; 9 9 10 10 type … … 29 29 procedure SetMaxCount(const AValue: Integer); 30 30 public 31 Items: TThreadList; 31 Items: TListObject; 32 Lock: TCriticalSection; 32 33 procedure Add(Group: string; Text: string); 33 34 procedure WriteToFile(Text: string); … … 57 58 58 59 procedure TDebugLog.SetMaxCount(const AValue: Integer); 59 var60 List: TList;61 I: Integer;62 60 begin 63 61 if FMaxCount = AValue then Exit; 64 62 FMaxCount := AValue; 65 List := Items.LockList;66 if List.Count > 0 then begin67 for I := AValue to List.Count - 1 do68 TDebugLogItem(List[I]).Free;69 L ist.Count := AValue;63 try 64 Lock.Acquire; 65 if Items.Count > FMaxCount then Items.Count := AValue; 66 finally 67 Lock.Release; 70 68 end; 71 Items.UnlockList;72 69 end; 73 70 74 71 procedure TDebugLog.Add(Group: string; Text: string); 75 72 var 76 I: Integer;77 List: TList;78 73 NewItem: TDebugLogItem; 79 74 begin … … 83 78 NewItem.Text := Text; 84 79 85 List := Items.LockList; 86 List.Insert(0, NewItem); 87 if List.Count > MaxCount then begin 88 TDebugLogItem(List.Items[List.Count - 1]).Free; 89 List.Delete(List.Count - 1); 90 end; 91 Items.UnlockList; 80 try 81 Lock.Acquire; 82 Items.Insert(0, NewItem); 83 if Items.Count > MaxCount then begin 84 Items.Delete(Items.Count - 1); 85 end; 92 86 93 if WriteToFileEnable then begin 94 if Group <> '' then Group := Group + '[' + Group + '] '; 95 WriteToFile(Group + Text); 87 if WriteToFileEnable then begin 88 if Group <> '' then Group := Group + '[' + Group + '] '; 89 WriteToFile(Group + Text); 90 end; 91 finally 92 Lock.Release; 96 93 end; 97 94 if Assigned(FOnNewItem) then … … 113 110 LogFile.WriteBuffer(Text[1], Length(Text)); 114 111 finally 115 LogFile.Free;112 FreeAndNil(LogFile); 116 113 end; 117 114 end; … … 120 117 begin 121 118 inherited; 122 Items := TThreadList.Create; 119 Items := TListObject.Create; 120 Lock := TCriticalSection.Create; 123 121 MaxCount := 100; 124 122 FileName := 'DebugLog.txt'; … … 127 125 128 126 destructor TDebugLog.Destroy; 129 var130 List: TList;131 I: Integer;132 127 begin 133 List := Items.LockList;134 for I := 0 to List.Count - 1 do135 TDebugLogItem(List[I]).Free;136 128 Items.Free; 129 Lock.Free; 137 130 inherited; 138 131 end;
Note:
See TracChangeset
for help on using the changeset viewer.