Below is another way to detect whether your program runs in the Delphi IDE. The symbol DebugHook is defined in a system unit (tested here with Delphi 5), so you do not need to add any units to the USES clause as shown in the example below.
program p;
begin
if DebugHook<>0 then
ShowMessage('Running in Delphi IDE');
end.