To declare a procedural constant,
specify the name of a function or procedure that is compatible with the
declared type of the constant. For example,
function
Calc(X, Y: Integer): Integer;
begin
...
end;
type
TFunction = function(X, Y: Integer): Integer;
const
MyFunction: TFunction = Calc;
Given these declarations, you can
use the procedural constant MyFunction in a function call:
I := MyFunction(5, 7)
You can also assign the value nil to a procedural constant.
要声明一个程序型常量,需要指定与声明的常量类型兼容的函数或过程的名称。例如,
function
Calc(X, Y: Integer): Integer;
begin
...
end;
type
TFunction = function(X, Y: Integer): Integer;
const
MyFunction: TFunction = Calc;
对于上面给出的声明,可以在函数调用中使用程序型常量MyFunction:
I := MyFunction(5, 7)
也可以将空指针nil赋给程序型常量。