2008-12-29 130 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的過濾器。