Delphi Language Guide Delphi for Microsoft Win32 Delphi for the Microsoft. Net framework



Yüklə 0,84 Mb.
Pdf görüntüsü
səhifə16/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   12   13   14   15   16   17   18   19   ...   294
DelphiLanguageGuide

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 the program 
greeting
 depends on a unit called 
Unit1
. Finally, the program
calls the 
PrintMessage
 procedure, passing to it the string Hello World! The 
PrintMessage
 procedure is defined
in 
Unit1
. Here is the source code for 
Unit1
, which must be saved in a file called Unit1.pas:
unit Unit1;
                    
interface
procedure PrintMessage(msg: string);
implementation;
9


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!

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   12   13   14   15   16   17   18   19   ...   294




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azkurs.org 2024
rəhbərliyinə müraciət

gir | qeydiyyatdan keç
    Ana səhifə


yükləyin