線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2078
推到 Plurk!
推到 Facebook!

請問GExperts的debug功能要怎麼使用呢?

答題得分者是:taishyang
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#1 引用回覆 回覆 發表時間:2009-07-07 10:39:07 IP:203.75.xxx.xxx 未訂閱
不知道在bcb上使用GExperts的人多不多
網路上的人大部份都說這軟體很好用,但都沒教這怎麼用
尤其是它的Debug功能,這一定要搭配GExperts才能夠使用嗎?
有人能教一下這怎麼用嗎?


===========================================
原文出处:在BCB下使用GExperts的Debug功能
GExperts是BCB的一个插件,其中有一项功能是Debug,非常好用。但是由于定义它的是pas文件(这个文件是GExperts安装目录下DbugIntf.pas),所以不能在BCB中直接使用。我把这个文件转换成C 文件,但是使用的时候注意把dbugintf.h文件copy到工程所在的目录中,直接在文件中用#include引用,不要添加到project中!
具体的使用方法还是看帮助吧!下面是转换后的文件。
[code cpp]
/*-----------------------------------------------------------------------------
Unit Name: dbugintf.h
Author: yuanhen
Email: yuanhen88@hotmail.com
yuanhen88@mail.china.com
Purpose: translate Delphi version to C Builder's
Date: 2003/06/05
Time: 20:42:08
History:
NOTE NOTE NOTE:
DON'T ADD this file to your project. Otherwise, this file should be include
to your project manually
-----------------------------------------------------------------------------*/
#ifndef DBUGINTF_H
#define DBUGINTF_H
#ifdef LINUX
#include
#endif LINUX
#include
#include
//---------------------------------------------------------------------------
// global variables
AnsiString MsgPrefix;
const char chrClearCommand = 3;
bool PastFailedAttemptToStartDebugWin = false;
const AnsiString Indentation = " ";
// declaration
void SendBoolean(const AnsiString &Identifier, const bool Value);
void SendDateTime(const AnsiString &Identifier, const TDateTime Value);
void SendDebugEx(const AnsiString &Msg, TMsgDlgType MType);
void SendDebug(const AnsiString &Msg);
void SendDebugClear();
void SendInteger(const AnsiString &Identifier, const int Value);
void SendMethodEnter(const AnsiString &MethodName);
void SendMethodExit(const AnsiString &MethodName);
void SendSeparator();
void SendDebugFmt(const AnsiString &Msg, const TVarRec *Args);
void SendDebugFmtEx(const AnsiString &Msg, const TVarRec *Args, TMsgDlgType MType);
HWND StartDebugWin();
// definition
void SendBoolean(const AnsiString &Identifier, const bool Value)
{
// Note: We deliberately leave "True" and "False" as
// hard-coded string constants, since these are
// technical terminology which should not be localised.
if (Value)
SendDebugEx(Identifier "= True", mtInformation);
else
SendDebugEx(Identifier "= False", mtInformation);
}
void SendDateTime(const AnsiString &Identifier, const TDateTime Value)
{
SendDebugEx(Identifier '=' DateTimeToStr(Value), mtInformation);
}
void SendDebugEx(const AnsiString &Msg, TMsgDlgType MType)
{
TCopyDataStruct CDS;
HWND DebugWin;
AnsiString MessageString;
#ifdef LINUX
const AnsiString MTypeStr[TMsgDlgType] =
{"Warning: ", "Error: ", "Information: ", "Confirmation: ", "Custom: "};
#endif LINUX
#ifdef LINUX
std::cout << "GX: " << MTypeStr[MType] << Msg << std::endl;
#endif LINUX
#ifndef LINUX
DebugWin = FindWindow("TfmDebug", NULL);
if (DebugWin == 0)
DebugWin = StartDebugWin();
if (DebugWin != 0)
{
MessageString = MsgPrefix Msg;
CDS.cbData = MessageString.Length() 4;
CDS.dwData = 0;
AnsiString com;
if (Msg == chrClearCommand)
{
com = chrClearCommand;
com = AnsiString(MType 1) MessageString;
com = '\0';
}
else
{
com = '\1';
com = com AnsiString(MType 1) MessageString;
com = com '\0';
}
CDS.lpData = com.c_str();
SendMessage(DebugWin, WM_COPYDATA, WPARAM(Application->Handle), LPARAM(&CDS));
}
#endif LINUX
}
void SendDebug(const AnsiString &Msg)
{
SendDebugEx(Msg, mtInformation);
}
void SendDebugClear()
{
SendDebug(chrClearCommand);
}
void SendInteger(const AnsiString &Identifier, const int Value)
{
SendDebugEx(AnsiString(Identifier " = " Value), mtInformation);
}
void SendMethodEnter(const AnsiString &MethodName)
{
MsgPrefix = MsgPrefix Indentation;
SendDebugEx("Entering " MethodName, mtInformation);
}
void SendMethodExit(const AnsiString &MethodName)
{
SendDebugEx("Exiting " MethodName, mtInformation);
MsgPrefix.Delete(1, Indentation.Length());
}
void SendSeparator()
{
const AnsiString SeparatorString = "------------------------------";
SendDebugEx(SeparatorString, mtInformation);
}
void SendDebugFmt(const AnsiString &Msg, const TVarRec *Args)
{
SendDebugEx(Msg.Format(Msg, Args, sizeof(Args)), mtInformation);
}
void SendDebugFmtEx(const AnsiString &Msg, const TVarRec *Args, TMsgDlgType MType)
{
SendDebugEx(Msg.Format(Msg, Args, sizeof(Args)), MType);
}
HWND StartDebugWin()
{
AnsiString DebugFilename;
char Buf[MAX_PATH 1];
TStartupInfo si;
TProcessInformation pi;
MsgPrefix = "";
HWND Result = 0;
if (PastFailedAttemptToStartDebugWin)
{
exit;
}
TRegIniFile *File = new TRegIniFile("\\Software\\GExperts");
__try
{
DebugFilename = File->ReadString("Debug", "FilePath", "");
}
__finally
{
delete File;
}
if (DebugFilename.Trim() == "")
{
GetModuleFileName(NULL, Buf, sizeof(Buf)-1);
DebugFilename = ExtractFilePath(StrPas(Buf)) "GDebug.exe";
}
if (DebugFilename.Trim() == "" || (!FileExists(DebugFilename)))
{
PastFailedAttemptToStartDebugWin = true;
exit;
}
memset(&si, '\0', sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOW;
if (!CreateProcess(DebugFilename.c_str(), NULL,
NULL, NULL,false, 0, NULL,
NULL, &si, &pi))
{
PastFailedAttemptToStartDebugWin = true;
exit;
}
__try
{
WaitForInputIdle(pi.hProcess, 3000); // wait for 3 seconds to get idle
}
__finally
{
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
Result = FindWindow("TfmDebug", NULL);
return Result;
}
#endif DBUGINTF_H
[/code]
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2009-07-07 12:01:31 IP:118.169.xxx.xxx 訂閱
剛剛試了一下,安裝完畢後會有Debug Window,執行後會有個小視窗
將你PO的程式碼另存成dbugintf.h

在BCB裡用下面的程式碼測試

#include "dbugintf.h"
void __fastcall TForm1::Button1Click(TObject *Sender)
{
SendDebugEx("test", mtInformation);
}
便會在Debug Window看到test字樣
這debug功能小弟覺得DebugView做得比較好 ^^

另外PO上來的程式碼因為站上顯示的問題,
&pi應該是 & pi
if (!CreateProcess(DebugFilename.c_str(), NULL,
NULL, NULL,false, 0, NULL,
NULL, &si, & pi)){
PastFailedAttemptToStartDebugWin = true;
exit;
}



===================引 用 GrandRURU 文 章===================
不知道在bcb上使用GExperts的人多不多
網路上的人大部份都說這軟體很好用,但都沒教這怎麼用
尤其是它的Debug功能,這一定要搭配GExperts才能夠使用嗎?
有人能教一下這怎麼用嗎?

編輯記錄
taishyang 重新編輯於 2009-07-07 12:03:04, 註解 無‧
taishyang 重新編輯於 2009-07-07 12:04:22, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2009-07-07 12:48:25 IP:203.75.xxx.xxx 未訂閱
有有有!
我看到跳出的小視窗了,是GExperts自帶的Debug Window

但…這與try...catch有什麼不同呢?

taishyang大所提到的 Debug View指的是BCB內建的Debug功能嗎?

另外,封裝的話也需要把GExperts裝到客戶端的電腦嗎?

===================引 用 taishyang 文 章===================
剛剛試了一下,安裝完畢後會有Debug Window,執行後會有個小視窗
將你PO的程式碼另存成dbugintf.h
編輯記錄
GrandRURU 重新編輯於 2009-07-07 12:52:59, 註解 無‧
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#4 引用回覆 回覆 發表時間:2009-07-07 12:52:26 IP:118.169.xxx.xxx 訂閱
DebugView是另外一家3rd公司出的run time debug工具,站上有討論以及範例
這你可以自己試試看^_^

應該不用裝到客戶的電腦,它會用FindWindow找DebugWindow,用SendMessage把資料丟過去
FindWindow找不到他會用CreateProcess去啟動DebugWindow,若還是沒有DebugWindow
自然就無法將訊息傳遞過去


===================引 用 GrandRURU 文 章===================
另外,封裝的話也需要把GExperts裝到客戶端的電腦嗎?


編輯記錄
taishyang 重新編輯於 2009-07-07 12:52:58, 註解 無‧
taishyang 重新編輯於 2009-07-07 14:26:08, 註解 無‧
GrandRURU
站務副站長


發表:240
回覆:1680
積分:1874
註冊:2005-06-21

發送簡訊給我
#5 引用回覆 回覆 發表時間:2009-07-07 17:25:25 IP:203.75.xxx.xxx 未訂閱
那家公司似乎已經m$買走了?
DebugView的確有比GExperts方便,不用再另外indclude .h文件,直上語法就可以了
謝謝taishyang大的解惑唷!

===================引 用 taishyang 文 章===================
DebugView是另外一家3rd公司出的run time debug工具,站上有討論以及範例
這你可以自己試試看^_^

系統時間:2024-04-25 12:12:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!