王朝网络
分享
 
 
 

在BCB下使用GExperts的Debug功能!

王朝other·作者佚名  2006-01-08
宽屏版  字体: |||超大  

GExperts是BCB的一个插件,其中有一项功能是Debug,非常好用。但是由于定义它的是pas文件(这个文件是GExperts安装目录下DbugIntf.pas),所以不能在BCB中直接使用。我把这个文件转换成C++文件,但是使用的时候注意把dbugintf.h文件copy到工程所在的目录中,直接在文件中用#include引用,不要添加到project中!

具体的使用方法还是看帮助吧!下面是转换后的文件。

/*-----------------------------------------------------------------------------

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 <iostream>

#endif LINUX

#include <vcl.h>

#include <Registry.hpp>

//---------------------------------------------------------------------------

// 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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有