Quick start manual

2-4
Delphi Language Guide
Example programs
The first line declares a program called Greeting. The {$APPTYPE CONSOLE} directive tells
the compiler that this is a console application, to be run from the command line. The
next line declares a variable called MyMessage, which holds a string. (Delphi has
genuine string data types.) The program then assigns the string “Hello world!” to the
variable MyMessage, and sends the contents of MyMessage to the standard output
using the Writeln procedure. (Writeln is defined implicitly in the System unit, which
the compiler automatically includes in every application.)
You can type this program into a file called Greeting.pas or Greeting.dpr and
compile it by entering
DCC32 Greeting
on a Windows-based system, or
dcc Greeting
on a Linux-based system. The resulting executable prints the message “Hello world!”
Note
In the previous and subsequent examples for Linux, dcc must be in your path, or you
must enter the full path when executing the dcc executable.
Aside from its simplicity, this example differs in several important ways from
programs that you are likely to write with Borland development tools. First, it is a
console application. Borland development tools are most often used to write
applications with graphical interfaces; hence, you would not ordinarily call Writeln.
Moreover, the entire example program (save for Writeln) is in a single file. In a typical
GUI application, the program heading—the first line of the examplewould be
placed in a separate project file that would not contain any of the actual application
logic, other than a few calls to routines defined in unit files.
A more complicated example
The next example shows a program that is divided into two files: a project file and a
unit file. The project file, which you can save as Greeting.dpr, looks like this:
program Greeting;
{$APPTYPE CONSOLE}
uses Unit1;
begin
PrintMessage('Hello World!');
end.
The first line declares a program called Greeting, which, once again, is a console
application. The uses Unit1; clause tells the compiler that Greeting includes a unit
called Unit1. Finally, the program calls the PrintMessage procedure, passing to it the
string “Hello World!” Where does the PrintMessage procedure come from? It’s