Solved

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

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 76
Working with hours 3 58
how to update exe applicatio from internet ? 6 80
Angular JS Route 3 72
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

831 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