方法作为传递的参数示例代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
vp = procedure of object;
TForm1 = class(TForm)
Button1: TButton;
CheckBox1: TCheckBox;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure P1;
procedure P2;
Procedure P3(a:vp);
end;
var
Form1: TForm1;
p:vp;
flag:boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
caption := '';
flag := CheckBox1.Checked;
if flag then
p:= p1
else p:= P2;
p3(p);
end;
procedure TForm1.P1;
begin
Caption := Caption + '-' + IntToStr(random(9));
end;
procedure TForm1.P2;
begin
Caption := Caption + IntToStr(random(9));
end;
procedure TForm1.P3(a: vp);
var
i:integer;
begin
for i := 0 to 20 do
a;
end;
end.