说干就干,今天翻译了Object Pascal的前面一部分,可惜后面的内嵌汇编等我不懂 (0分)

  • 主题发起人 主题发起人 Qingzhong
  • 开始时间 开始时间
Q

Qingzhong

Unregistered / Unconfirmed
GUEST, unregistred user!
第二章 程序和单元
第一节 程序和单元概述
A program is constructed from source-code modules called units. Each unit is stored in its own file and compiled separately;
compiled units are linked to create an application. Units allow you to
程序是由源代码模块,即单元组成。每一个单元保存在一个单独的文件中并且被分别编译;编译后单元被连结以生成应用程序。单元可以让你:
divide large programs into modules that can be edited separately.
将一个程序划分成若干个可单独编辑的模块。
create libraries that you can share among programs.
创建可在程序间共享的库。
distribute libraries to other developers without making the source code available.
将库分发给其它的开发者而不用向他们提供源代码。
In traditional Pascal programming, all source code, including the main program, is stored in .pas files. Borland tools use a project (.dpr) file to store the Main?program, while most other source code resides in unit (.pas) files. Each application or project consists of a single project file and one or more unit files. (Strictly speaking, you needn't explicitly use any units in a project, but all programs automatically use the System unit.) To build a project, the compiler needs either a source file or a compiled unit file for each unit.
传统的Pascal编程,所有的源代码,包括主程序,都保存在.pas文件中。Borland开发工具使用了项目文件(.dpr)来保存主程序,其它大多数源代码仍留在单元文件(.pas)中。每一个应用程序或者说项目由一个项目文件和若干个单元文件组成(严格地说,在一个项目中,你可以不必使用单元文件,但所有的程序会自动引用System单元)。要编译一个项目,编译器需要每一个单元的源代码文件或者编译后文件。
第二节 程序的结构和句法
A program contains
a program heading,
a uses clause (optional), and
a block of declarations and statements.
一个程序包含
一个程序头,
一个uses子句(可选),以及
一个申明和实现语句块
The program heading specifies a name for the program. The uses clause lists units used by the program. The block contains declarations and statements that are executed when the program runs. The IDE expects to find these three elements in a single project (.dpr) file.
程序头指定了程序的名称。uses子句列出了程序引用的单元。语句块包含了申明和实现,它们将在程序运行时被执行。IDE期望在一个单一的项目文件(.dpr)中找到这三个部分。
The example below shows the project file for a program called Editor.
下面的例子是一个名叫Editor的程序的项目文件。
1 program Editor;
2
3 uses
4 Forms, {change to QForms in Linux}
5 REAbout in 'REAbout.pas' {AboutBox},
6 REMain in 'REMain.pas' {MainForm};
7
8 {$R *.res}
9
10 begin
11 Application.Title := 'Text Editor';
12 Application.CreateForm(TMainForm, MainForm);
13 Application.Run;
14 end.

Line 1 contains the program heading. The uses clause is on lines 3 through 6. Line 8 is a compiler directive that links the project'S resource file into the program. Lines 10 through 14 contain the block of statements that are executed when the program runs. Finally, the project file, like all source files, ends with a period.
第一行是程序头。3-6行是uses子句,第8行是一个编译器指示符用于将项目的资源文件连结入程序。第10-14行包含了程序运行时将执行的语句块。最后项目文件以句号(.)结束(就像所有的源代码文件一样)。
This is, in fact, a fairly typical project file. Project files are usually short, since most of a program's logic resides in its unit files. Project files are generated and maintained automatically, and it is seldom necessary to edit them manually.
这是一个相当典型的项目文件。项目文件通常很短,因为大多数程序的逻辑都在单元文件中实现。项目文件是自动创建并维护的,很少需要手工去编辑它。
第三节 程序头
The program heading specifies the program's name. It consists of the reserved word program, followed by a valid identifier, followed by a semicolon. The identifier must match the project file name. In the previous example, since the program is called Editor, the project file should be called EDITOR.dpr.
程序头指明了程序的名称。它由保留字program,跟上一个正确的标识符,最后跟上一个分号(;)构成。该标识符必须与项目文件的文件名一致。以前节的例子来说,由于程序名是Editor,项目文件就必须命名为EDITOR.dpr。
In standard Pascal, a program heading can include parameters after the program name:
在标准Pascal中,程序头可以在程序名后写参数,例如:
program Calc(input, output);
Borland's Object Pascal compiler ignores these parameters.
但是Borland的Object Pascal编译器忽略这些参数。
identifier 标识符

第四节 uses子句
The uses clause lists units that are incorporated into the program. These units may in turn have uses clauses of their own. For more information about the uses clause, see Unit references and the uses clause.
uses子句列出了包含到程序中的单元。这些被引用的单元可以在自己的单元中再去引用其它的单元。
第五节 语句块
The block contains a simple or structured statement that is executed when the program runs. In most programs, the block consists of a compound statement cracketed between the reserved words begin
and end.
those component statements are simply method calls to the project's Application object. (Every project has an Application variable that holds an instance of TApplication, TWebApplication, or TServiceApplication.) The block can also contain declarations of constants, types, variables, procedures, and functions;
these declarations must precede the statement part of the block.
语句块包含了一条简单语句或者一个复合语句,这些语句将在程序运行时被执行。对大多数程序,该语句块是一个由保留字begin
和end包围的复合语句。这些语句仅简单地调用项目的Application对象(每一个项目都有一个Application变量,它包含了TApplication或者TWebApplication或者TServiceApplication的一个实例)。该语句块也可以申明常量、类型、变量、过程和函数,这些申明必须在程序运行时被执行的语句块之前。
simple statement 简单语句
structured statement 复合语句?
compound statement 复合语句
第六节 单元结构和句法
A unit consists of types (including classes), constants, variables, and routines (functions and procedures). Each unit is defined in its own unit (.pas) file.
单元由类型(包括类)、常量、变量和程序(函数和过程)组成。每一个单元在自己的单元文件(.pas)中定义。
A unit file begin
s with a unit heading, which is followed by the interface, implementation, initialization, and finalization sections. The initialization and finalization sections are optional. A skeleton unit file looks like this:
每一个单元文件以单元头开始,然后是interface, implementation, initialization, and finalization 等小节。
unit Unit1;

interface

uses {在这列出引用的单元}

{界面部分在这说明}

implementation

uses {在这列出引用的单元}

{在这写出程序的实现}

initialization
{初始化小节}

finalization
{终结化小节}

end.

The unit must conclude with the word end followed by a period.
单元以end跟上一个句号(.)结束。
Finalization 终结化
第七节 单元头
The unit heading specifies the unit's name. It consists of the reserved word unit, followed by a valid identifier, followed by a semicolon. For applications developed using Borland tools, the identifier must match the unit file name. Thus, the unit heading
单元头指定了本单元的名称。它由保留字unit,跟上一个正确的标识符,最后跟上一个分号(;)构成。对使用 Borland工具开发的应用程序,该标识符必须与单元文件的文件名一致。例如:
unit MainForm;
would occur in a source file called MAINFORM.pas, and the file containing the compiled unit would be MAINFORM.dcu.
它将出现在源代码文件MAINFORM.pas中,该单元文件编译后单元为MAINFORM.dcu。
Unit names must be unique within a project. Even if their unit files are in different directories, two units with the same name cannot be used in a single program.
单元名称在一个项目内必须唯一。即使单元文件在不同目录里,两个同名的单元文件也不能出现在一个项目内。
第八节 界面小节
The interface section of a unit begin
s with the reserved word interface and continues until the begin
ning of the implementation section. The interface section declares constants, types, variables, procedures, and functions that are available to clients, that is, to other units or programs that use the unit where they are declared. These entities are called public because a client can access them as if they were declared in the client itself.
一个单元的界面小节以保留字interface开始,至implementation小节开始处结束。在interface小节申明的常量、类型、变量、过程和函数对其它引用本小节的客户(即其它单元或程序)是可用的。他们是公开的,客户可以存取他们,就如同在客户自身内申明的一样。
The interface declaration of a procedure or function includes only the routine's heading. The block of the procedure or function follows in the implementation section. Thus procedure and function declarations in the interface section work like forward declarations, although the forward directive isn't used.
在interface小节仅仅申明过程或函数的程序头,实现他们的语句块在implementation小节完成。在interface小节申明的过程或函数就像forward申明,但不需要使用forward指示符。
The interface declaration for a class must include declarations for all class members.
在interface内申明一个类时,必须包括该类的全部类成员的申明。
The interface section can include its own uses clause, which must appear immediately after the word interface. For information about the uses clause, see Unit references and the uses clause.
interface小节可以有自己的uses子句,它必须紧跟在interface一词的后面。
第九节 实现小节
The implementation section of a unit begin
s with the reserved word implementation and continues until the begin
ning of the initialization section or, if there is no initialization section, until the end of the unit. The implementation section defines procedures and functions that are declared in the interface section. Within the implementation section, these procedures and functions may be defined and called in any order. You can omit parameter lists from public procedure and function headings when you define them in the implementation section;
but if you include a parameter list, it must match the declaration in the interface section exactly.
实现小节以保留字implementation开始,直到initialization小节开始,或者当没有initialization小节时,至本单元结束处为止。implementation小节定义了在interface小节申明的过程或函数。在implementation小节,这些过程或函数可以以任何次序出现。在implementation小节定义公共过程或函数时,你可以省略他们的参数列表,但若你包含了参数列表,则必须与interface小节申明的完全一致。
In addition to definitions of public procedures and functions, the implementation section can declare constants, types (including classes), variables, procedures, and functions that are private to the unit,that is, inaccessible to clients.
在implementation小节,除了可以定义公共过程或函数外,还可以申明常量、类型(包括类)、变量、过程和函数,他们对本单元是私有的,对其它客户是不可存取的。
The implementation section can include its own uses clause, which must appear immediately after the word implementation. For information about the uses clause, see Unit references and the uses clause.
implementation小节可以包括自己的uses子句,它必须立即出现在implementation一词之后。
第十节 初始化小节
The initialization section is optional. It begin
s with the reserved word initialization and continues until the begin
ning of the finalization section or, if there is no finalization section, until the end of the unit. The initialization section contains statements that are executed, in the order in which they appear, on program start-up. So, for example, if you have defined data structures that need to be initialized, you can do
this in the initialization section.
初始化小节是可选的,它以保留字initialization开始,直到finalization小节开始,或者当没有finalization小节时,至本单元结束处为止。initialization小节包含了在程序启动时执行的语句,他们按出现的顺序执行。例如,你定义了需要初始化的数据结构,你可以在initialization小节来完成它的初始化。
The initialization sections of units used by a client are executed in the order in which the units appear in the client抯 uses clause.
当客户程序通过uses子句引用各单元时,各被引用单元的initialization按照各单元在客户程序uses子句中出现的先后顺序执行。
第十一节 终结化小节
The finalization section is optional and can appear only in units that have an initialization section. The finalization section begin
s with the reserved word finalization and continues until the end of the unit. It contains statements that are executed when the main program terminates. Use the finalization section to free resources that are allocated in the initialization section.
Finalization sections are executed in the opposite order from initializations. For example, if your application initializes units A, B, and C, in that order, it will finalize them in the order C, B, and A.
终结化小节是可选的,只有在有initialization小节的单元出现。finalization小节以保留字finalization开始到本单元结束处结束。它包含了主程序被终止后要执行的语句。可使用finalization小节释放在initialization小节分配的资源。finalization小节按照initialization小节执行的相反顺序执行。例如,如果你的程序按照单元A,B,C的顺序初始化,则程序按C,B,A顺序终结化。
Once a unit's initialization code starts to execute, the corresponding finalization section is guaranteed to execute when the application shuts do
wn. The finalization section must therefore be able to handle incompletely initialized data, since, if a runtime error occurs, the initialization code might not execute completely.
一旦某单元的初始化代码被执行,当程序终止时,终结化小节保证会被执行。因此,终结化小节必须能处理不完全的初始化数据,因为如果有运行时错误,初始化代码就有可能没有被全部执行。
 
不错,可惜我的英语不行,不然我也加入
 
My english id pool,so i must learning more english!
 
精神可嘉,如果不出版的话实在可惜,呵
 
接受答案了.
 
后退
顶部