Originale-mail to me for new edition

 

Parameters

 

Most procedure and function headers include a parameter list. For example, in the header

function Power(X: Real; Y: Integer): Real;

the parameter list is (X: Real; Y: Integer).

A parameter list is a sequence of parameter declarations separated by semicolons and enclosed in parentheses. Each declaration is a comma-delimited series of parameter names, followed in most cases by a colon and a type identifier, and in some cases by the = symbol and a default value. Parameter names must be valid identifiers. Any declaration can be preceded by one of the reserved words var, const, and out (see Parameter semantics). Examples:

(X, Y: Real)

(var S: string; X: Integer)

(HWnd: Integer; Text, Caption: PChar; Flags: Integer)

(const P; I: Integer)

The parameter list specifies the number, order, and type of parameters that must be passed to the routine when it is called. If a routine does not take any parameters, omit the identifier list and the parentheses in its declaration:

procedure UpdateRecords;

begin

 ...

end;

Within the procedure or function body, the parameter names (X and Y in the first example above) can be used as local variables. Do not redeclare the parameter names in the local declarations section of the procedure or function body.

String parameters

Array parameters

 

Topic groups

 

See also

Calling procedures and functions

Declaring procedures and functions: Overview

Procedures and functions: Overview

Untyped parameters

 

 

译文

 

参数

 

大多数过程和函数首部都包括一个参数列表(parameter list),例如,在函数首部

function Power(X: Real; Y: Integer): Real;

中,参数列表是(X: Real; Y: Integer)

参数列表是一个参数声明序列,声明之间以分号隔开,参数列表由圆括号封装。每个声明是一个参数名序列,参数名之间以逗号隔开,大多数情况下跟随一个冒号(:)和一个类型标识符,某些情况下还跟随一个等号(=)和一个缺省值(见缺省参数)。参数名必需是有效标识符。所有声明之前都可以含有保留字varconstout之一(见参数语义)。例如:

(X, Y: Real)

(var S: string; X: Integer)

(HWnd: Integer; Text, Caption: PChar; Flags: Integer)

(const P; I: Integer)

当例程被调用时,参数列表指定了必需传递给例程的参数的个数、顺序以及类型。如果一个例程不接受任何参数,那么在例程声明中可以忽略标识符列表和圆括号:

procedure UpdateRecords;

begin

 ...

end;

在过程或函数主体中,参数名(上面例子中的XY)可以被作为局部变量使用。在过程或函数主体的局部声明中不要对参数名进行再声明(事实上编译器也不允许这样)。

串参数

数组参数

 

主题组

 

相关主题

调用过程和函数

声明过程和函数:概述

过程和函数:概述

无类型参数