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ə15/294
tarix02.01.2022
ölçüsü0,84 Mb.
#41395
1   ...   11   12   13   14   15   16   17   18   ...   294
DelphiLanguageGuide

Example Programs
The examples that follow illustrate basic features of Delphi programming. The examples show simple applications
that would not normally be compiled from the IDE; you can compile them from the command line.
A Simple Console Application
The program below is a simple console application that you can compile and run from the command prompt.
program greeting;
                                                
  {$APPTYPE CONSOLE}
    
  var MyMessage string;
8


     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.

Yüklə 0,84 Mb.

Dostları ilə paylaş:
1   ...   11   12   13   14   15   16   17   18   ...   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