Solved

How do I execute a section of code only when running under the debugger

Posted on 2011-03-09
4
290 Views
Last Modified: 2012-05-11
I tried using
{$IFDEF DEBUG}
...
{$ENDIF}

but it appears to get fired in the compiled exe as well.

Thanks for your help

Daniel
0
Comment
Question by:DanielManchester
  • 2
4 Comments
 
LVL 14

Expert Comment

by:systan
ID: 35085477
hi
try to read that link;
http://stackoverflow.com/questions/147719/delphi-ifdebug-equivalent
in D2007 the define DEBUG begins
0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 35085478
function IsDebuggerPresent: BOOL; stdcall; external 'kernel32.dll';

procedure TForm1.Button1Click(Sender: TObject);
begin
  if IsDebuggerPresent then ShowMessage('Exists')
  else ShowMessage('not Exists')
end;

http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_23199714.html
0
 
LVL 14

Expert Comment

by:systan
ID: 35085517
I tried this code from the link;
unit Unit1;
{$define debug}
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.btn1Click(Sender: TObject);
begin
 {$IFDEF DEBUG}
  ShowMessage('my conditional IS defined!');
  {$ELSE}
  ShowMessage('my conditional is NOT defined!');
  {$ENDIF}

  {$IFNDEF DEBUG}
  ShowMessage('My conditional is explicitly NOT defined');
  {$ENDIF}

end;

end.

Open in new window

0
 

Author Closing Comment

by:DanielManchester
ID: 35085825
Just what I was looking for.  Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now