B
baoling
Unregistered / Unconfirmed
GUEST, unregistred user!
我在学习写控件,发现一个问题,请教各位大侠:
不太好说明,只好劳烦大侠看两个例子:
先看整型属性
type
TMYpanel = class(TCustomPanel)
private
FABC: integer;
procedure SetFABC(value: integer);
protected
procedure myrun; //
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ABC: integer read FABC write SetFABC; //自定义的整型属性
end;
.....
.....
procedure TMypanel.SetFABC(value: integer);
begin
Fabc:=value;
myrun;
end;
//如果对Tmypanel对象实例属性赋值
如: mypanel1.ABC:=100 则会调用myrun的过程
***************************************************************************
type
TDClass = class(TPersistent) //自定义的对象类型
private
FDA, FDB: integer;
protected
public
procedure Assign(source: TPersistent); override;
published
property DA: integer read FDA write FDA;
property DB: integer read FDA write FDB;
end;
type
TMYpanel = class(TCustomPanel)
private
FABC: TDClass;
procedure SetFABC(value: TDClass);
protected
procedure myrun; //
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ABC: TDClass read FABC write SetFABC; //自定义的对象类型的属性
end;
.....
procedure TDClass.Assign(source: TPersistent);//①
begin
if source is TDClass then
begin
FDA := TDClass(source).DA;
FDB := TDClass(source).DB;
end;
end;
.....
procedure TMypanel.SetFABC(value: TDClass); //②
begin
if Assigned(value) then
begin
Fabc.Assign(Value);
myrun;
end;
end;
//问题:
如果对Tmypanel对象实例属性赋值:
mypanel1.ABC.DA:=100 不会调用myrun的过程,① ②都没有被调用,
我的myrun应该放在哪里?我的意图是只要属性变了就要'动作'MYrun
不太好说明,只好劳烦大侠看两个例子:
先看整型属性
type
TMYpanel = class(TCustomPanel)
private
FABC: integer;
procedure SetFABC(value: integer);
protected
procedure myrun; //
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ABC: integer read FABC write SetFABC; //自定义的整型属性
end;
.....
.....
procedure TMypanel.SetFABC(value: integer);
begin
Fabc:=value;
myrun;
end;
//如果对Tmypanel对象实例属性赋值
如: mypanel1.ABC:=100 则会调用myrun的过程
***************************************************************************
type
TDClass = class(TPersistent) //自定义的对象类型
private
FDA, FDB: integer;
protected
public
procedure Assign(source: TPersistent); override;
published
property DA: integer read FDA write FDA;
property DB: integer read FDA write FDB;
end;
type
TMYpanel = class(TCustomPanel)
private
FABC: TDClass;
procedure SetFABC(value: TDClass);
protected
procedure myrun; //
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ABC: TDClass read FABC write SetFABC; //自定义的对象类型的属性
end;
.....
procedure TDClass.Assign(source: TPersistent);//①
begin
if source is TDClass then
begin
FDA := TDClass(source).DA;
FDB := TDClass(source).DB;
end;
end;
.....
procedure TMypanel.SetFABC(value: TDClass); //②
begin
if Assigned(value) then
begin
Fabc.Assign(Value);
myrun;
end;
end;
//问题:
如果对Tmypanel对象实例属性赋值:
mypanel1.ABC.DA:=100 不会调用myrun的过程,① ②都没有被调用,
我的myrun应该放在哪里?我的意图是只要属性变了就要'动作'MYrun