Solved

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

Posted on 2011-03-09
4
292 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

856 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