How can I get an application to write debug text to the Event Log window in the Delphi IDE (Borland Developer Studio 2006)?
How does one change the color of the text
OutputDebugString('Hello,World');
I think you may need to add Windows to your 'uses' list. Not 100% sure on that...
The text colour can't be changed as far as I know: It's a feature of the Delphi IDE that it adds additional messages into that window for thread start/stop, DLL load/unload, with their own specific colour.
Yes, you can use OutputDebugString
.
If you want get more powerful features for controlling and managing debug output, such as a highlighting filter, you should use DebugView.
Note: DebugView can't capture the debug log when you run your application in the Delphi IDE.
Apart from what has been said (i.e. OutputDebugString
and using DebugView instead of the built-in log viewer), you can change the color of messages in the log view via the Options. The easiest way to get there is by right-clicking in the log pane and selecting "Properties" from the context menu. On the tab that will appear you can set the color to use for "Output Debug Strings" from the "Colors" section. Obviously this will change the color of all messages emitted via OutputDebugString
- it will not allow individual coloring. For that you'd better use DebugView's filters.
procedure Write2EventLog(Source,Msg: string);
var h: THandle;
ss: array [0..0] of pchar;
begin
ss[0] := pchar(Msg);
h := RegisterEventSource(nil, // uses local computer
pchar(Source)); // source name
if h <> 0 then
ReportEvent(h, // event log handle
EVENTLOG_ERROR_TYPE, // event type
0, // category zero
0, // event identifier
nil, // no user security identifier
1, // one substitution string
0, // no data
@ss, // pointer to string array
nil); // pointer to data
DeregisterEventSource(h);
end;