您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

Delphi使用一个函数或过程当做另一个函数的参数

时间:2011/9/3 15:31:22 点击:

  核心提示:type TFunctionParameter = function(const value : integer) : string;...function One(const value : int...
type
   TFunctionParameter = function(const value : integer) : string;

...

function One(const value : integer) : string;
begin
   result := IntToStr(value) ;
end;

function Two(const value : integer) : string;
begin
   result := IntToStr(2 * value) ;
end;

function DynamicFunction(f : TFunctionParameter) : string;
begin
   result := f(2006) ;
end;

...

//Example usage:

var
   s : string;
begin
   s := DynamicFunction(One) ;
   ShowMessage(s) ; //will display "2006"

   s := DynamicFunction(Two) ;
   ShowMessage(s) ; // will display "4012"
end;

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号