Browse Source

* Added the ability to un-register the eventlog message-file

git-svn-id: trunk@15586 -
joost 15 years ago
parent
commit
8d9f3feafa

+ 6 - 0
packages/fcl-base/src/dummy/eventlog.inc

@@ -44,6 +44,12 @@ begin
   Result:=True;
   Result:=True;
 end;
 end;
 
 
+Function TEventLog.UnRegisterMessageFile : Boolean;
+
+begin
+  Result:=True;
+end;
+
 function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
 function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
 begin
 begin
   Result:=0;
   Result:=0;

+ 1 - 0
packages/fcl-base/src/eventlog.pp

@@ -70,6 +70,7 @@ Type
     Destructor Destroy; override;
     Destructor Destroy; override;
     Function EventTypeToString(E : TEventType) : String;
     Function EventTypeToString(E : TEventType) : String;
     Function RegisterMessageFile(AFileName : String) : Boolean; virtual;
     Function RegisterMessageFile(AFileName : String) : Boolean; virtual;
+    Function UnRegisterMessageFile : Boolean; virtual;
     Procedure Log (EventType : TEventType; Msg : String); {$ifndef fpc }Overload;{$endif}
     Procedure Log (EventType : TEventType; Msg : String); {$ifndef fpc }Overload;{$endif}
     Procedure Log (EventType : TEventType; Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif}
     Procedure Log (EventType : TEventType; Fmt : String; Args : Array of const); {$ifndef fpc }Overload;{$endif}
     Procedure Log (Msg : String); {$ifndef fpc }Overload;{$endif}
     Procedure Log (Msg : String); {$ifndef fpc }Overload;{$endif}

+ 6 - 0
packages/fcl-base/src/unix/eventlog.inc

@@ -95,6 +95,12 @@ begin
   Result:=True;
   Result:=True;
 end;
 end;
 
 
+Function TEventLog.UnRegisterMessageFile : Boolean;
+
+begin
+  Result:=True;
+end;
+
 function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
 function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
 begin
 begin
   Result:=0;
   Result:=0;

+ 14 - 3
packages/fcl-base/src/win/eventlog.inc

@@ -15,6 +15,9 @@
 
 
 uses windows;
 uses windows;
 
 
+const
+  SKeyEventLog = 'SYSTEM\CurrentControlSet\Services\EventLog\Application\%s';
+
 Function TEventLog.DefaultFileName : String;
 Function TEventLog.DefaultFileName : String;
 
 
 begin
 begin
@@ -70,7 +73,6 @@ end;
 Function TEventLog.RegisterMessageFile(AFileName : String) : Boolean;
 Function TEventLog.RegisterMessageFile(AFileName : String) : Boolean;
 
 
 Const
 Const
-  SKeyEventLog = 'SYSTEM\CurrentControlSet\Services\EventLog\Application\%s';
   SKeyCategoryCount       = 'CategoryCount';
   SKeyCategoryCount       = 'CategoryCount';
   SKeyEventMessageFile    = 'EventMessageFile';
   SKeyEventMessageFile    = 'EventMessageFile';
   SKeyCategoryMessageFile = 'CategoryMessageFile';
   SKeyCategoryMessageFile = 'CategoryMessageFile';
@@ -85,8 +87,6 @@ Var
 begin
 begin
   SecurityAttributes:=nil;
   SecurityAttributes:=nil;
   CheckIdentification;
   CheckIdentification;
-  If AFileName='' then
-    AFileName:=ParamStr(0);
   ELKey:=Format(SKeyEventLog,[IDentification]);
   ELKey:=Format(SKeyEventLog,[IDentification]);
   Result:=RegCreateKeyExA(HKEY_LOCAL_MACHINE,
   Result:=RegCreateKeyExA(HKEY_LOCAL_MACHINE,
                           PChar(ELKey),0,'',
                           PChar(ELKey),0,'',
@@ -96,6 +96,8 @@ begin
                           pdword(@Disposition))=ERROR_SUCCESS;
                           pdword(@Disposition))=ERROR_SUCCESS;
   If Result then
   If Result then
     begin
     begin
+      If AFileName='' then
+        AFileName:=ParamStr(0);
       Value:=4;
       Value:=4;
       Result:=Result and (RegSetValueExA(Handle,PChar(SKeyCategoryCount),0,REG_DWORD,@Value,sizeof(DWORD))=ERROR_SUCCESS);
       Result:=Result and (RegSetValueExA(Handle,PChar(SKeyCategoryCount),0,REG_DWORD,@Value,sizeof(DWORD))=ERROR_SUCCESS);
       Value:=7;
       Value:=7;
@@ -105,6 +107,15 @@ begin
     end;
     end;
 end;
 end;
 
 
+Function TEventLog.UnRegisterMessageFile : Boolean;
+
+Var
+  ELKey : String;
+begin
+  ELKey:=Format(SKeyEventLog,[IDentification]);
+  Result:=RegDeleteKeyA(HKEY_LOCAL_MACHINE,pchar(ELKey));
+end;
+
 function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
 function TEventLog.MapTypeToCategory(EventType: TEventType): Word;
 begin
 begin
   If (EventType=ETCustom) then
   If (EventType=ETCustom) then