About the author
I was looking at the Stackoverflow question - Program both as Console and GUI and noted that there wasn't an example for Delphi, so I created the following.
program
TestConsoleGUI;
{$APPTYPE GUI}
{$R *.res}
uses
System
.
SysUtils,
VCL
Forms,
Winapi
Windows,
TestUnit
in
'TestUnit.pas'
{Form1}
;
function
AttachConsole(
const
dwProcessId: THandle): BOOL; stdcall; external kernel32 name
'AttachConsole'
var
bFreeConsole:
Boolean
begin
if
ParamCount =
0
then
try
{ TODO -oUser -cConsole Main : Insert code here }
Application
Initialize;
MainFormOnTaskbar :=
True
CreateForm(TForm1, Form1);
Run;
except
on
E: Exception
do
// Handle exception here
end
else
bFreeConsole :=
False
ParamStr(
1
) =
'/CONSOLE'
bFreeConsole := AttachConsole(THandle(-
))
or
AllocConsole;
WriteLn
(
'Hello world'
);
finally
bFreeConsole
FreeConsole;