From 09e3b42610283500021d234624d13eea67ec69f7 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Thu, 19 Mar 2015 08:56:52 +0000 Subject: [PATCH] FS#23 - Access Violation when using sub-categories --- Test/source/MainFrm.pas | 19 ++++++++++++++++++- X2Log.Decorator.pas | 4 +++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Test/source/MainFrm.pas b/Test/source/MainFrm.pas index 47994c8..d0dfcfa 100644 --- a/Test/source/MainFrm.pas +++ b/Test/source/MainFrm.pas @@ -271,8 +271,25 @@ end; 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 - FLog.Category('Test').Info(edtMessage.Text); + FLog.Info('Categories'); + Category1(FLog.Category('Test')); + FLog.Info('/Categories'); end; diff --git a/X2Log.Decorator.pas b/X2Log.Decorator.pas index 27c0151..0d9237b 100644 --- a/X2Log.Decorator.pas +++ b/X2Log.Decorator.pas @@ -8,6 +8,8 @@ uses type + TX2LogCategoryDecoratorClass = class of TX2LogCategoryDecorator; + TX2LogCategoryDecorator = class(TInterfacedObject, IX2Log) private FCategoryName: string; @@ -106,7 +108,7 @@ end; function TX2LogCategoryDecorator.Category(const ACategory: string): IX2Log; begin if Assigned(DecoratedLog) then - Result := Self.Create(DecoratedLog, GetCategory(ACategory)); + Result := (TX2LogCategoryDecoratorClass(Self.ClassType)).Create(DecoratedLog, GetCategory(ACategory)); end;