在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
在匿名函数中,可以修改本地变量的值 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 procedure (x, y: Integer); TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private procedure plusXandY(x, y: Integer; intSum: TIntSum); { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var lResult: Integer; begin plusXandY(40, 30, procedure (x, y: Integer) begin lResult := lResult + x + y; end); ShowMessageFmt('x + y = %d', [lResult]); // 调用三次,结果是210 end; procedure TForm1.plusXandY(x, y: Integer; intSum: TIntSum); begin intSum(x, y); intSum(x, y); intSum(x, y); end; end.
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论