Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Debug memo.

Status
Not open for further replies.

Tremorblue

Programmer
Apr 30, 2004
56
GB
I wanted to create a debug version of my application.

How can I create a macro that is compiled in only when I create the debug version. I would like to pass messages to a memo when in debug mode, but dont want any residual code when not in use.

Heres what I have so far...

#define DEBUG

#ifdef DEBUG
void __fastcall TForm1::DebugMessage(AnsiString aMessage)
{
Memo1->Lines->Add(aMessage);
}
#else
void __fastcall TForm1::DebugMessage(AnsiString aMessage)
{

}
#endif

#define DBG(a) Form1->DebugMessage((AnsiString)a);

Trouble is when its not in use debugmessage still gets called :(

/TB
 
Your code looks ok to me, not sure what you mean by:

"Trouble is when its not in use debugmessage still gets called :("

DebugMessage gets called if DEBUG is or isn't defined, it's just that the debug function does something and the non-debug does nothing. (I'm sure you knew that though). If you really want as little residual code as possible, don't even make the function call though. Handle the conditional compilation in the macro definition itself, then you don't have the overhead of a function call:
Code:
#ifdef DEBUG
#define DBG(a) Form1->DebugMessage((AnsiString)a);
#else
#define DBG(a)
#endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top