begin
MyMessage := 'Hello world!';
Writeln(MyMessage);
end.
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
to produce a Win32 executable, or
dccil greeting
to produce a managed .NET executable. In either case, the resulting executable prints the message Hello world!
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 example would 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.
Dostları ilə paylaş: