怎样可以知道控件里的事件没有定义?(10分)

  • 主题发起人 主题发起人 lwaif
  • 开始时间 开始时间
L

lwaif

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

type
Tmy=procedure(aa:integer;S: string) of object;
Taa=class
procedure ttt();
constructor Create;

private
{ Private declarations }
FOnMyEv:Tmy;
public
{ Public declarations }
published
property OnMyEv : Tmy read FOnMyEv write FOnMyEv;
end;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
procedure ddd(t:integer;aaa:string);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
constructor Taa.Create;
begin
inherited;
end;
procedure Taa.ttt();
var i:integer;
begin
for i:=0 to 1000 do
OnMyEv(i,inttostr(i));
end;

procedure TForm1.Button1Click(Sender: TObject);
var bb:Taa;
begin
bb:=Taa.Create;
//bb.OnMyEv:=ddd; //这里注释掉程序就运行这里出错了
try
bb.ttt;
finally
bb.Free;
end;
end;
procedure TForm1.ddd(t:integer;aaa:string);
begin
memo1.Lines.Add(aaa);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
showmessage('hi');
end;

end.

在OnMyEv没有定义时怎样可以让程序正常通过呢?
 
if assigned(xxx) then
 
应该是这样吧,VCL内部就是这么判断的。
 
接受答案了.
 
后退
顶部