Question

How can I detect if my application is running under the IDE "Delphi 2007 .Net", there is something like DebugHook?

Bye.

Was it helpful?

Solution

Answer my own question.

uses System.Diagnostics; 

function IDEDelphiNetRunning:Boolean; 
Begin 
Result:=Debugger.IsAttached; 
End; 

works fine for me.

Bye.

OTHER TIPS

The IsDebuggerPresent() WinAPI call.

Something like:

Function IDEIsRunning : boolean;
begin
  result := DebugHook <> 0;
end;

Might Suit.

The JEDI JclDebug.pas unit contains the following:

function IsDebuggerAttached: Boolean;
var
  IsDebuggerPresent: function: Boolean; stdcall;
  KernelHandle: THandle;
  P: Pointer;
begin
  KernelHandle := GetModuleHandle(kernel32);
  @IsDebuggerPresent := GetProcAddress(KernelHandle, 'IsDebuggerPresent');
  if @IsDebuggerPresent <> nil then
  begin
    // Win98+ / NT4+
    Result := IsDebuggerPresent
  end
  else
  begin
    // Win9x uses thunk pointer outside the module when under a debugger
    P := GetProcAddress(KernelHandle, 'GetProcAddress');
    Result := DWORD(P) < KernelHandle;
  end;
end;

I found this more general answer, from embarcadero

Use the IsDebuggerPresent() WinAPI call. Example in C++:

if (IsDebuggerPresent())
    Label1->Caption = "debug";
else
    Label1->Caption = "no debug";
function IsDebugMode():Boolean;
begin
  Result:=False;
 {$IFDEF DEBUG}
  Result:=True;
 {$ENDIF}
end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top