How To Create Your First Console Application!
A Delphi Console program is different from DOS because it is able to call Windows API functions and also use its resources.
Okay the first thing we need to do is start a new project.
Save it as Project1 or whatever you want to name it.
You will see the new Form and Unit, we do not need the Form for a Console application so we need to get rid of it and the way to do this is to (with your mouse cursor) select (from the File menu) Project (this may be different for different versions of Delphi) and then click on Remove From Project.
You have only one Form in your project so select it and click on OK.
A 'Save Changes To Unit1.Pas ' dialog box may appear at this stage,
click 'No'.
At this point you have removed Form1 from your project, you now have
a 'Formless Application'.
Have a look at the source code for your project in the Delphi Code Editor.
You should see this:
uses
Forms;
{$R *.RES}
begin
Application.Initialize;
Application.Run;
end.
{$R *.RES}
begin
Application.Initialize;
Application.Run;
end.
uses
Forms; //Delete this!
{$R *.RES}
begin
Application.Initialize; // Delete
this!
Application.Run;
// Delete this!
end.
{$AppType Console}
{$R *.RES}
begin
end.
{$AppType Console}
{$R *.RES}
begin
WriteLn('My first Console Application!');
end.
{$AppType Console}
{$R *.RES}
begin
WriteLn('My first Console Application!');
ReadLn;
end.
Remark 1
In Delphi 5
File | New | Console Application
will create the program template for you, without the editing needed in the tip.
Remark 2
One Application can be both a Console Application and a GUI Application.
In this case a additional Console Window
is automatically created and assigned to standard input and standard
output. This can be very usefull for debugging via
simple WriteLn statements.
One caveat exists: Closing the console windows terminates the application.
Remark 3
Windows ME has still the DOS Window, but you can't boot into DOS mode any longer. For a pure DOS environment you neet a start diskette.
Remark 4
If you start a Console application form the DOS prompt or a batch file
you have to use the start command to create a new
console window for the application. Otherwise it takes over the DOS
prompt window from which it was started.
For task tray applications you have to use start in batch jobs but not
in the DOS prompt window (NT 4).
So they seem to be somewhere between a pure GUI application and a Console
application.
Remark 5
Console Applications are still fullblown Windows applications and no
MSDOS applications.
Regards from Germany
Franz-Leo