LogMessage limitation

Giganews Newsgroups
Subject:LogMessage limitation
Posted by: Robert Small (…@noisp.com)
Date:Tue, 06 Mar 2007

I have been trying to get a Service running, and as part of the
journey I needed to write messages to the Windows event log.

I eventually came across the excellent article by Dennis Passmore
(Delphi Magazine #94) which got me going.

I then discovered that that Delphi6 implementation of
TEventLogger.LogMessage (see below)is a wrapper for the Windows API
ReportEvent, and it is hard coded for only 1 replaceable string,
whereas the ReportEvent function actually takes any number of
replaceable strings.

Is TEventLogger.LogMessage() fixed in later versions?

procedure TEventLogger.LogMessage(Message: String; EventType: DWord;
  Category: Word; ID: DWord);
var
  P: Pointer;
begin
  P := PChar(Message);
  if FEventLog = 0 then
    FEventLog := RegisterEventSource(nil, PChar(FName));
  ReportEvent(FEventLog, EventType, Category, ID, nil, 1, 0, @P, nil);
end;

--
Bob Small

Replies