Delphi匿名方法
来源:互联网 发布:注册淘宝网店铺流程 编辑:程序博客网 时间:2024/05/16 07:20
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
//首先声明匿名方法的类型
TIntSum = reference to function (x, y: Integer): Integer;
//引用方法的声明
//TIntProcedure = function (x, y: Integer): Integer of object;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
function plusXandY(x, y: Integer; intSum: TIntSum): integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ShowMessageFmt('x + y = %d',
[plusXandY(10,
15,
function (x, y: Integer): Integer
begin
Result := x + y;
end)
]);
ShowMessageFmt('x + y = %d',
[plusXandY(20,
1500,
function (x, y: Integer): Integer
begin
Result := x * y;
end)
]);
end;
function TForm1.plusXandY(x, y: Integer; intSum: TIntSum): integer;
begin
Result := intSum(x, y);
end;
end.
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs;
type
//首先声明匿名方法的类型
TIntSum = reference to function (x, y: Integer): Integer;
//引用方法的声明
//TIntProcedure = function (x, y: Integer): Integer of object;
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
function plusXandY(x, y: Integer; intSum: TIntSum): integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ShowMessageFmt('x + y = %d',
[plusXandY(10,
15,
function (x, y: Integer): Integer
begin
Result := x + y;
end)
]);
ShowMessageFmt('x + y = %d',
[plusXandY(20,
1500,
function (x, y: Integer): Integer
begin
Result := x * y;
end)
]);
end;
function TForm1.plusXandY(x, y: Integer; intSum: TIntSum): integer;
begin
Result := intSum(x, y);
end;
end.
阅读全文
0 0
- Delphi 2010 匿名方法
- Delphi匿名方法
- delphi: reference to(匿名方法)
- Delphi 2009 中的匿名方法(reference to)
- Delphi中的匿名方法和闭包
- Delphi 2009 中的匿名方法(reference to) 研究
- 匿名类+匿名方法
- 匿名方法
- 匿名方法
- 匿名方法
- 匿名方法
- 匿名方法
- 匿名方法
- 匿名方法
- 匿名方法
- TDD实践之路--泛型和匿名方法在DELPHI单元测试中的妙用
- 匿名类和匿名方法
- C#匿名方法zz
- 流水账笔记:PE文件格式(重定位表)
- java作业
- 口胡【NOIP2012DAY1】借教室
- 使用Navicat生成ER关系图并导出
- IPv6 解说 ,与IPv4的同异
- Delphi匿名方法
- 关于char, wchar_t, TCHAR, _T,L,TEXT,_TEXT,LPSTR,LPCSTR,PWSTR,PCWSTR,LPTSTR,LPCTSTR的区别
- linux小练习4
- 重学数据结构 链表(工程文件)算法2.8 2.9 2.10 2.11
- 例2.1b
- [牛客网算法笔记]分糖果问题
- Openstack中说的二层和三层switch
- 练习17.10.3
- 【codevs 1135】选择客栈