2009-06-29 215 views

回答

3

回答我自己的问题。

uses System.Diagnostics; 

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

适合我。

再见。

4

IsDebuggerPresent()WinAPI调用。

+0

这不是真正的问题的答案不过,因为运行的Delphi下的应用程序和在其他调试器下运行它不能通过这种方式进行区分。也许这对于OP来说并不重要,但是这个问题应该有不同的措辞。在System.Diagnostics中还有Debugger.Is附加,无需调用Windows API。 – mghie 2009-06-30 04:18:04

2

喜欢的东西:

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

可能适合。

+0

Alister,DebugHook在“Delphi 2007.Net”中不存在,所以寻找一些替代方案。 – RRUZ 2009-06-30 03:39:31

+0

那么,我正在寻找如何做与OP完全相同的东西......但在Delphi 5中。所以很自然地,这对我来说非常合适。 :) +1 – 2010-06-14 15:10:46

+0

这适用于Delphi 7 ;-) – NetVicious 2016-01-18 16:43:53

0

我发现这个更一般的答案,从embarcadero

使用IsDebuggerPresent() WinAPI的电话。 实施例在C++:

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

的JEDI JclDebug.pas单元包含以下内容:

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; 
-3
function IsDebugMode():Boolean; 
begin 
    Result:=False; 
{$IFDEF DEBUG} 
    Result:=True; 
{$ENDIF} 
end; 
相关问题