type tfun=function(a,b):integer;
procedure add(a,b):integer;
begin
add := a+b;
end;
function calc(fun:tfun;a:integer;b:integer):integer;
begin
calc = fun(a,b);
end;//
calc(add);
也许可以
procedure add(a,b):integer;
begin
add := a+b;
end;
function calc(fun:tfun;a:integer;b:integer):integer;
begin
calc = fun(a,b);
end;//
calc(add);
也许可以
不过我觉得他的有错
这里错了吧?应该是
type tfun=function(integer;integer):integer;
声明的是函数或者过程的参数的类型,而不是名字。以上假设是两个integer变量。其实看看那些delphi事件的help就行了,事件帮助里有写着事件的定义代码,照着写就行了。哦,还有。楼上的例子中,calc的调用方法是: result=calc(@add,1,1)。要用符号“@”得到add的地址作为参数。
type TFun=function(a:integer;b:integer):integer;如果是类的方法,要在尾部加上of object.详细看Delphi help 的 Procedural types页
源代码种有很多地方都用了回吊函数