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.
easier solution:
program YourProgram;
{$DEFINE MakeConsoleApp}
{$IFDEF MakeConsoleApp}
{$APPTYPE CONSOLE}
{$ENDIF}
[....]
{$IFDEF MakeConsoleApp} WriteLn('Text in a Console'); {$ENDIF}
so anytime you want to make you application not show a console you would just change {$DEFINE MakeConsoleApp} to { } or {.$DEFINE MakeConsoleApp}
It does not work in *.dpr file, but it is OK in a unit (call MakeBeep from console *.dpr):
unit Unit1;
interface
uses
SysUtils;
procedure MakeBeep;
implementation
procedure MakeBeep;
begin
{$IFDEF CONSOLE}
beep;
{$ENDIF}
end;
If you select "Generate console application" from the linker options, 'CONSOLE' is defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With