Originale-mail to me for new edition

 

Calling procedures and functions

 

When you call a procedure or function, program control passes from the point where the call is made to the body of the routine. You can make the call using the routine’s declared name (with or without qualifiers) or using a procedural variable that points to the routine. In either case, if the routine is declared with parameters, your call to it must pass parameters that correspond in order and type to the routine’s parameter list. The parameters you pass to a routine are called actual parameters, while the parameters in the routine’s declaration are called formal parameters.

When calling a routine, remember that

·expressions used to pass typed const and value parameters must be assignment-compatible with the corresponding formal parameters.

·expressions used to pass var and out parameters must be identically typed with the corresponding formal parameters, unless the formal parameters are untyped.

·only assignable expressions can be used to pass var and out parameters.

·if a routine’s formal parameters are untyped, numerals and true constants with numeric values cannot be used as actual parameters.

When you call a routine that uses default parameter values, all actual parameters following the first accepted default must also use the default values; calls of the form SomeFunction(,,X) are not legal.

You can omit parentheses when passing all and only the default parameters to a routine. For example, given the procedure

procedure DoSomething(X: Real = 1.0; I: Integer = 0; S: string = '');

the following calls are equivalent.

DoSomething();

DoSomething;

 

Open array constructors

 

Topic groups

 

See also

Declaring procedures and functions: Overview

Default parameters

Parameters: Overview

Procedural types in statements and expressions

Procedures and functions: Overview

 

 

译文

 

调用过程和函数

 

调用过程或函数时,程序控制将由调用点传递给例程主体。可以通过使用例程的声明名称(含有或不含限定词)或者通过使用指向例程的程序型变量来实现调用。不管使用哪种方式,如果例程声明中含有参数,那么在调用时必需根据参数列表向例程以正确的顺序和类型传递参数。传递到例程中的参数叫做实际参数(actual parameters),而例程声明中的参数叫做形式参数(formal parameters)。

调用例程时应切记:

·用于传递有类型的常量(const)参数和值(value)参数的表达式必需与相应的形式参数是赋值兼容的。

·用于传递var参数和out参数的表达式,其类型必需与相应形式参数的类型等同,除非形式参数是无类型的。

·只有可赋值的表达式可以被用于传递var参数和out参数。

·如果例程的形式参数是无类型的,那么数字和含数值的真实常量都不能作为实际参数传递。

调用使用了缺省参数值的例程时,跟随在第一个接受缺省值之后的所有实际参数,都必需使用缺省值;形如 SomeFunction(,,X) 的调用是不合法的。

向例程传递所有参数并且所有的参数都使用缺省值时,甚至可以忽略圆括号。例如,对于如下过程

procedure DoSomething(X: Real = 1.0; I: Integer = 0; S: string = '');

下面的调用是等价的:

DoSomething();

DoSomething;

 

开放数组构造器

 

主题组

 

相关主题

声明过程和函数:概述

缺省参数

参数:概述

语句和表达式中的程序型类型

过程和函数:概述