1
0
mirror of synced 2024-11-21 19:03:50 +00:00

FS#23 - Access Violation when using sub-categories

This commit is contained in:
Mark van Renswoude 2015-03-19 08:56:52 +00:00
parent 437655693e
commit 09e3b42610
2 changed files with 21 additions and 2 deletions

View File

@ -271,8 +271,25 @@ end;
procedure TMainForm.btnCategoryClick(Sender: TObject); procedure TMainForm.btnCategoryClick(Sender: TObject);
procedure Category2(ALog: IX2Log);
begin
ALog.Info(edtMessage.Text);
end;
procedure Category1(ALog: IX2Log);
begin
ALog.Info('Category 1');
Category2(ALog.Category('Sub-category'));
ALog.Info('/Category 1');
end;
begin begin
FLog.Category('Test').Info(edtMessage.Text); FLog.Info('Categories');
Category1(FLog.Category('Test'));
FLog.Info('/Categories');
end; end;

View File

@ -8,6 +8,8 @@ uses
type type
TX2LogCategoryDecoratorClass = class of TX2LogCategoryDecorator;
TX2LogCategoryDecorator = class(TInterfacedObject, IX2Log) TX2LogCategoryDecorator = class(TInterfacedObject, IX2Log)
private private
FCategoryName: string; FCategoryName: string;
@ -106,7 +108,7 @@ end;
function TX2LogCategoryDecorator.Category(const ACategory: string): IX2Log; function TX2LogCategoryDecorator.Category(const ACategory: string): IX2Log;
begin begin
if Assigned(DecoratedLog) then if Assigned(DecoratedLog) then
Result := Self.Create(DecoratedLog, GetCategory(ACategory)); Result := (TX2LogCategoryDecoratorClass(Self.ClassType)).Create(DecoratedLog, GetCategory(ACategory));
end; end;