tags:

views:

342

answers:

3

I've heard that some custom component authors use an RTL routine that checks to see if Delphi is running in order to set up shareware restrictions. Does anyone know what this routine is? Checking obvious names like "DelphiRunning" or "IsDelphiRunning" doesn't turn up anything useful.

+2  A: 

Here's the code-snippet.

Moayad Mardini
Copy and paste horror. This code snippet should be cleaned up or forgotten. Really.
François
+2  A: 

You can use DebugHook <> 0 from your component code. DebugHook is a global variable (IIRC, it's in the Systems unit) that's set by the Delphi/RAD Studio IDE, and couldn't be set from anywhere else.

There are other techniques (FindWindow() for TAppBuilder, for instance), but DebugHook takes all of the work out of it.

Ken White
+9  A: 

There are 2 different ideas here:
- Delphi is up and running
- The application is running under the debugger

The common way to test if Delphi is running is to check the presence of known IDE Windows which have a specific classname like TAppBuilder or TPropertyInspector.
Those 2 works in all version of Delphi IIRC.

If you want to know if your application is running under the debugger, i.e. launched normally from the IDE with "Run" (F9) or attached to the debugger while already running, you just have to test the DebugHook global variable.
Note that "Detach from program" does not remove the DebugHook value, but "Attach to process" sets it.

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

function IsOrWasUnderDebugger: Boolean;
begin
  Result := DebugHook <> 0;
end;

If the goal is to restrict the use of a trial version of your component to when the application is being developped, both have flaws:
- Hidden windows with the proper Classname/Title can be included in the application
- DebugHook can be manually set in the code

François