用两个继承类,如下:
TEditA=Class(Tedit);
private
FA:string;
...
published
property A:string read FA write FA;
...TEditB=Class(Tedit);
private
FB:string;
...
published
property B:string read FB write FB;
...组合一个新的类
TEditC=Class(TCustomControl)
private
TA:TEditA;
TB:TeditB;
Public
Constructor Create(AOWner:Tcomponent);override;
...constructor TEditC.Create(AOWner: Tcomponent);
begin
inherited;
TA:=TEditA.Create(Self);
TA.Width:=50;
TA.Height:=27;
TA.Top:=0;
TA.Visible:=true;
TA.Parent:=Self;
TA.Anchors:=[akTop, akLeft, akRight, akBottom];
TA.Left:=0;
TA.ReadOnly:=True; TB:=TEditB.Create(Self);
TB.Width:=50;
TB.Height:=27;
TB.Top:=0;
TB.Visible:=true;
TB.Parent:=Self;
TB.Anchors:=[akTop, akLeft, akRight, akBottom];
TB.Left:=TA.Width;
Self.Width:=TA.Height+TB.Height;
Self.Height:=27;
End;请问:TEditC中如何继承TEditA中FA和TEditB中FB属性(显示在控件的属性栏中)
(除了再TEditC中重复定义外)
TEditA=Class(Tedit);
private
FA:string;
...
published
property A:string read FA write FA;
...TEditB=Class(Tedit);
private
FB:string;
...
published
property B:string read FB write FB;
...组合一个新的类
TEditC=Class(TCustomControl)
private
TA:TEditA;
TB:TeditB;
Public
Constructor Create(AOWner:Tcomponent);override;
...constructor TEditC.Create(AOWner: Tcomponent);
begin
inherited;
TA:=TEditA.Create(Self);
TA.Width:=50;
TA.Height:=27;
TA.Top:=0;
TA.Visible:=true;
TA.Parent:=Self;
TA.Anchors:=[akTop, akLeft, akRight, akBottom];
TA.Left:=0;
TA.ReadOnly:=True; TB:=TEditB.Create(Self);
TB.Width:=50;
TB.Height:=27;
TB.Top:=0;
TB.Visible:=true;
TB.Parent:=Self;
TB.Anchors:=[akTop, akLeft, akRight, akBottom];
TB.Left:=TA.Width;
Self.Width:=TA.Height+TB.Height;
Self.Height:=27;
End;请问:TEditC中如何继承TEditA中FA和TEditB中FB属性(显示在控件的属性栏中)
(除了再TEditC中重复定义外)
property a read Ta ;
property b read tb;就通过Self.a.a和self.b.b来访问了
property a read Ta write SetA;
property b read tb write SetB;SetA(value:a)
begin a.assign(value); end;SetA(value:b)
begin b.assign(value); end;
\这样你在对象察看器中就可以看到这两个对象的属性了。