Console Applications in Lazarus
A console application is one that interacts primitively with a text
screen (80 characters wide x 25 lines high). Console apps are one-window,
text-based programs that use white text on a black background.
To create a console application, firstly Launch Lazarus, then from the
PROJECT menu REMOVE FROM PROJECT the default Unit1 file, then
OK.
From the VIEW menu, select UNITS, and from the list, choose
PROJECT1 (which is the project file for this application):
From the FILE menu, select SAVE PROJECT AS and nominate a folder
and project name such as "HelloWorld" and OK that.
Remember that Lazarus owns the project and the project name, so
you have to let it change it for you during the save as process:
To nominate the project as a CONSOLE application, you need to include
a compiler directive that tells it so:
When you compile your program it will generate an .EXE file that can
then be run outside of Lazarus.
In the above example, you will notice it ends with a readln.
One of the peculiarities of a Console application is that when it has
stopped running, the DOS window it opened for the output and input of
this application is automatically closed - this is a pain if you actually
want to read the stuff in that window.
When the readln is encountered, you application waits for you
to press the ENTER key before terminating and closing the window:
Unfortunately, many of the nice things that conventional Pascal uses
to manage the text screen (like clrscr, keypressed, gotoxy and so on
are not available in a console-based application - it does, however,
provide a way of running most other conventional pascal code.