procedure PrintMessage(msg: string);
begin
Writeln(msg);
end;
end.
Unit1
defines a procedure called
PrintMessage
that takes a single string as an argument and sends the string
to the standard output. (In Delphi, routines that do not return a value are called procedures. Routines that return a
value are called functions.) Notice that
PrintMessage
is declared twice in
Unit1
. The first declaration, under the
reserved word interface, makes
PrintMessage
available to other modules (such as
greeting
) that use
Unit1
.
The second declaration, under the reserved word implementation, actually defines
PrintMessage
.
You can now compile Greeting from the command line by entering
dcc32 greeting
to produce a Win32 executable, or
dccil greeting
to produce a managed .NET executable.
There is no need to include
Unit1
as a command-line argument. When the compiler processes greeting.dpr, it
automatically looks for unit files that the
greeting
program depends on. The resulting executable does the same
thing as our first example: it prints the message Hello world!
Dostları ilə paylaş: