You can write console mode programs, also called command line programs, programs that usually does not use Windows' graphical user interface, using Delphi.
- Create a new application using "File | New Application"
- Go to the "Project Manager" ("View | Project Manager")
- Remove the default form from the project (highlight the unit and hit DELETE -- do not save changes)
- Go to "Project Source" ("View | Project Source")
- Edit your project source file:
- Remove code inside "begin" and "end"
- Replace the "Forms" unit in the "uses" section with "SysUtils"
- You probably don't need to load the resource file -- remove "{$R *.RES}"
- Finally place "{$apptype console}" in a line by itself right after the "program" statement.
- Remove code inside "begin" and "end"
program console;
{$apptype console}
uses
SysUtils;
begin
{ add your code here... }
WriteLn( 'hello, world!' );
end.
{$apptype console}
uses
SysUtils;
begin
{ add your code here... }
WriteLn( 'hello, world!' );
end.
Listing #1 : Delphi code. Download console (0.24 KB).
{$IFDEF CONSOLE}
{... add your console mode code here ...}
{$ENDIF}
{... add your console mode code here ...}
{$ENDIF}
Listing #2 : Delphi code. Download ifdef (0.19 KB).
if( IsConsole )then
begin
{... add your console mode runtime code here ...}
end;
begin
{... add your console mode runtime code here ...}
end;
Listing #3 : Delphi code. Download iscnsole (0.21 KB).