Search code examples
delphiconsole-applicationcompile-timeconditional-compilation

Delphi {$IFDEF CONSOLE} Problem


I just tried

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

begin
  {$IFDEF CONSOLE}
    beep;
  {$ENDIF}
end.

and expected to hear a beep during runtime, but not. The following test works, though:

  if IsConsole then
    beep;

Why doesn't the compile-time test work? As far as I can understand from this doc, it sure should work.


Solution

  • If you select "Generate console application" from the linker options, 'CONSOLE' is defined.