2009-06-29 7 views

risposta

3

Rispondi alla mia domanda.

uses System.Diagnostics; 

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

funziona bene per me.

Ciao.

4

La chiamata WinAPI IsDebuggerPresent().

+0

Questo non è realmente una risposta alla domanda se, come esegue l'applicazione sotto Delphi e eseguirlo con qualsiasi altro debugger non può essere distinto in questo modo. Forse non è importante per l'OP, ma la domanda avrebbe dovuto essere formulata in modo diverso allora. Inoltre c'è Debugger.IsAttached in System.Diagnostics, non c'è bisogno di chiamare l'API di Windows. – mghie

2

Qualcosa di simile:

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

potrebbe soddisfare.

+0

Alister, DebugHook non esiste in "Delphi 2007.Net", quindi cerca qualche alternativa. – RRUZ

+0

Beh, stavo cercando come fare esattamente la stessa cosa di OP ... ma in Delphi 5. Quindi naturalmente questo ha funzionato perfettamente per me. :) +1 –

+0

Funziona su Delphi 7 ;-) – NetVicious

0

ho trovato questa risposta più generale, da embarcadero

Utilizzare la chiamata IsDebuggerPresent() WinAPI. Esempio in C++:

if (IsDebuggerPresent()) 
    Label1->Caption = "debug"; 
else 
    Label1->Caption = "no debug"; 
2

L'unità JEDI JclDebug.pas contiene i seguenti:

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; 
+1

La domanda è rivolta in particolare al debugger "Delphi 2007.net", non solo a un debugger. –

-3
function IsDebugMode():Boolean; 
begin 
    Result:=False; 
{$IFDEF DEBUG} 
    Result:=True; 
{$ENDIF} 
end; 
+3

Questo non ti dice se stai usando il debugger. Ti dice semplicemente se DEBUG è stato definito in fase di compilazione. Quindi hai postato una risposta totalmente sbagliata a una domanda di 6 anni che già aveva più risposte corrette esistenti. –