Jac*_*ień 5 delphi function-pointers function
不确定tittle是否正确但我需要做的是在一些集合中存储指向指定函数的指针.我这样做就像声明变量一样
SomeFunctionName: string
Run Code Online (Sandbox Code Playgroud)
当然这种类型不能是一个字符串,问题是它究竟应该是什么?
您通常会使用函数指针变量.例如:
type
TProcedure = procedure;
procedure MyProc1;
begin
end;
procedure MyProc2;
begin
end;
var
Proc: TProcedure;
.....
Proc := MyProc1;
Proc();//calls MyProc1
Proc := MyProc2;
Proc();//calls MyProc2
Run Code Online (Sandbox Code Playgroud)
这是可以想象的最简单的例子.您可以指定具有参数列表,对象类型方法等的过程类型.阅读语言指南的" 过程类型"主题中的更多内容.