Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if code is run from IDE

Tags:

ide

delphi

I have the following function that I use to check if my code is run from the IDE or not What is really frustrating is that from time to time the function returns False even if the code is run from IDE. And the fact that I can't find any common denominator for when it works OK and when it doesn't Anyone got an idea as how to fix this function or a whole other method of doing this check. (I use the function to make a menu with test functions available during development and hide them to end user)

function IDERunning: Bool;
begin
  Result := (FindWindow('TAppBuilder', nil) > 0) and
    (FindWindow('TPropertyInspector', 'Object Inspector') > 0);
end;

I use Delphi XE8

like image 608
OZ8HP Avatar asked Dec 02 '22 13:12

OZ8HP


1 Answers

It depends on exactly what you want to test:

  • Use IsDebuggerPresent to test if any user mode debugger is attached to your process.
  • Test if DebugHook is non-zero to determine that the program is running under the Delphi IDE debugger.

Note that when DebugHook is non-zero, then IsDebuggerPresent will return true, but the reverse is not always the case. There are debuggers other than the IDE debugger.

like image 194
David Heffernan Avatar answered Dec 10 '22 03:12

David Heffernan