Part 4 compile file (page 9)

xiaoxiao2021-03-06  34

Part 4 compile file (page 9)

A more complex example is a program example that is displayed and is split to 2 files. A project file, a unit file. You can save the project file as greeting.dpr, which looks like this: Program Greeting; {$ appty console} Uses unit1; beginprintMessage ('Hello World!'); END. The first line describes the program name Greeting, It is another console application. Uses Unit1; This sentence tells the compiler that this program relysses a unit file named Unit1. Finally, this program is stolen, passed to him a string "Hello World!", And PrintMessage is defined in the Unit1 file. This is the source code of the Until, must be saved in a file named Unit1.PAS. Unit Unit1; InterfaceProcedure; Implementation; Procedure PrintMessage (MSG: String); BeginWriteln (MSG); end; End.Unit1 Defines a process called PrintMessage. Enter a variable of a string and display this variable to the standard output window. (In Delphi, the program is not returned by the value is a process. The program that returns a value is called a function.) Note that PrintMessage is defined 2 times in Unit1. First definition, after keyword interface, PrintMessage is valid in other modules of Unit1. The second definition, after the keyword importation, the definition of PrintMessage is implemented. You are now entering and compiling Greeting DCC32 Greeting from the command line to generate a Win32 executable, or Dccil Greeting will generate an executable file under the .NET. There is no need to include Unit1 in the command line. When the compiler generates Greeting.dpr, you can automatically find the unit files rely on the Greeting program. The result is the same as the first example: Print Message Hello World!

Posted on 2004-12-

转载请注明原文地址:https://www.9cbs.com/read-76968.html

New Post(0)