2008-12-29 124 views
9

如何获取应用程序以将调试文本写入Delphi IDE(Borland Developer Studio 2006)中的事件日志窗口?写入Delphi中的事件日志

如何改变文本的颜色?

+0

使用dbgview可以有颜色,滤镜等。 – Harriv 2008-12-29 16:05:22

回答

26

OutputDebugString('Hello,World');

我想你可能需要将Windows添加到你的“用途”列表。不是100%肯定...

据我所知,文本颜色无法更改:这是Delphi IDE的一个功能,它向线程启动/停止,DLL加载的窗口中添加了额外的消息/卸载,具有自己的特定颜色。

8

是的,您可以使用OutputDebugString

如果您想获得更强大的功能来控制和管理调试输出,例如突出显示过滤器,您应该使用DebugView

注意:当您在Delphi IDE中运行应用程序时,DebugView无法捕获调试日志。

7
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; 
+3

Delpi IDE“事件日志”窗口与Windows事件日志无关。令人困惑,我知道! – Roddy 2008-12-30 23:42:40

3

除了说了些什么(即OutputDebugString和使用DebugView中,而不是内置的日志查看器),你可以更改消息的颜色通过选项日志查看。最简单的方法是在日志窗格中右键单击并从上下文菜单中选择“属性”。在出现的选项卡上,您可以设置颜色以用于“颜色”部分中的“输出调试字符串”。显然这将改变通过OutputDebugString发出的所有消息的颜色 - 它不允许单独着色。为此,最好使用DebugView的过滤器。