Delphi coding hints and tips.

Creating a non GUI DOS application with Delphi

It is possible to create a non GUI DOS application with Delphi. You may wish to do this in order to create some command line utility that does not require the overhead of a graphical user interface. An example of such a utility is grep.exe (regular expression pattern matching tool) which come with later versions of Delphi, you will find it in the bin directory.

Below is a step by step guide of how to create a simple DOS console application within Delphi:

  1. Create a new application.

  2. Close the blank form created and do not save it when prompted.

  3. View the project source and replace it with the following:

    program Project1;
     {$APPTYPE 
    CONSOLE}
    begin 
      Writeln( 'Hello world' );
      ReadLn; 
    end. 
  4. The directive $APPTYPE tells the compile to generate a console application to run from a command line. This is the same as having the Project | Options dialog Linker tab 'Generate Console Application' option switched on.

  5. Build and Run.

All this program does is display 'Hello world' and then wait for you to press any key on the keyboard. The total size of the resulting executable is only 16k.

Note: With Delphi 5 there is a simple wizard that creates a console application for you. Select File | New.. from the main menu and in the New Items dialog under the New tab will be a 'Console Application' wizard that saves you having to it by hand as above.