测试代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TMyClass =Class
private
Fenable:Boolean;
Fonchange:TNotifyEvent;
procedure SetEnable(const Value:boolean);
public
published
property Enable:boolean read Fenable write SetEnable;
property OnEnableChange:TNotifyEvent read Fonchange write Fonchange;
end;
TForm1 = class(TForm)
btn1: TButton;
edt1: TEdit;
btn2: TButton;
procedure btn2Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{ TForm1 }
{ TMyClass }
procedure TMyClass.SetEnable(const Value:boolean);
begin
if Value<>Fenable then
begin
Fenable:=value;
Fonchange(self)
//调用事件函数。
end;
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
ShowMessage('MyClass boolean property Changed');
end;
procedure TForm1.btn1Click(Sender: TObject);
var
c:Tmyclass;
begin
c:=Tmyclass.Create;
c.enable :=false;
c.OnEnableChange:=btn2Click
// 设置触发事件
c.Enable :=True
//改变属性值。
c.Free;
end;
end.