当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++ Builder教程

在BCB下使用GExperts的Debug功能

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

具体的使用方法还是看帮助吧!下面是转换后的文件。
/*-----------------------------------------------------------------------------
Unit Name: dbugintf.h
Author:    yuanhen
Email:     [email protected]
            [email protected]
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);

共2页 首页 上一页 1 2 下一页 尾页 跳转到
相关内容
赞助商链接