Delphi Console Applications

By John, DelphiLand Team on March 16, 2005

In Reply to: Re: stuck on my assignment (very beginner) posted by glenn on March 16, 2005:

: I have done this code, but it doesnt seem to work :(

I noticed that Delphi is being used a lot for teaching Pascal. Delphi was developed originally for writing *Windows* applications with a "Graphical User Interface" (GUI). But you can also use it for writing console applications, programs without a GUI.

A console application runs in a "console window". The visual controls of the VCL are not used in console applications. Input and output are handled with commands such as Read, ReadLn, Write and WriteLn.

The source code for a console application usually is contained in one single textfile, saved as a .DPR file, a "Delphi Project" file. There are no DFM files, because there are no "forms".

This project file can be written, compiled and tested in Delphi's Integrated Development Environment (IDE), just as any other Delphi application. To compile it, just use the menu Run / Run, or simply press F9. Here's an example:

program ConsApp;
{$APPTYPE CONSOLE}
uses
  SysUtils;
begin
  writeln('This is a Console Application');
  writeln('Press the ENTER key to stop the program');
  readln;
end. 

The line {$APPTYPE CONSOLE} in the source code tells Delphi that the program is to be compiled as a console application. In our example, the resulting executable file is CONSAPP.EXE and it can be run from the command line (in old times known as the "MS-DOS prompt" or "DOS window").

Very soon, we will devote some tutorials to console applications. Watch DelphiLand's "Mini Tutorial Projects" in the section "Code snips".

Greetings,
John, DelphiLand Team


 

Delphi Forum :: Tutorials :: Source code :: Tips