delphi 回调函数例子 用函数过程作为参数

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,ComCtrls, StdCtrls;

type
  TFunc = procedure() of object;
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
   function myTest(f:TFunc):string;
   procedure abc();
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.abc;
begin
  showmessage('这是回调函数测试');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   myTest(abc);
end;

function TForm1.myTest(f:TFunc):string;
begin
   f();
end;

end.

  

posted @ 2018-04-20 09:33  刀小爱  阅读(205)  评论(0)    收藏  举报