Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

758 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