我该如何让应用程序将调试文本写入Delphi IDE(Borland Developer Studio 2006)的事件日志窗口?
如何更改文本颜色?
我该如何让应用程序将调试文本写入Delphi IDE(Borland Developer Studio 2006)的事件日志窗口?
如何更改文本颜色?
OutputDebugString('Hello,World');
我认为您可能需要在“uses”列表中添加Windows。但我不确定…
据我所知,文本颜色无法更改:这是Delphi IDE的一个特性,它会将线程启动/停止、DLL加载/卸载等额外消息添加到该窗口中,并具有自己特定的颜色。
是的,你可以使用OutputDebugString
。
如果你想要更强大的控制和管理调试输出的功能,比如高亮过滤器,你应该使用DebugView。
注意:当你在Delphi IDE中运行应用程序时,DebugView无法捕获调试日志。
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;
OutputDebugString
和使用DebugView替代内置日志查看器),您可以通过选项更改日志视图中消息的颜色。最简单的方法是在日志窗格中右键单击,然后从上下文菜单中选择“属性”。在出现的选项卡上,您可以在“颜色”部分设置“输出调试字符串”要使用的颜色。显然,这将更改通过OutputDebugString
发出的所有消息的颜色-它不会允许个别着色。为此,最好使用DebugView的过滤器。