编辑:我的意思是,当我在对象检查器中查看字体时,它有一个小加号,我可以单击以设置字体名称“times new roman”,字体大小“10”等等.如果我使用错误的术语,Sorrry,这就是我所谓的“子属性”.
解决方法 您所要做的就是创建一个新的已发布属性,该属性指向已发布属性的类型.检查此代码
type TCustomType = class(TPersistent) //this type has 3 published propertIEs private Fcolor : Tcolor; fheight: Integer; FWIDth : Integer; public procedure Assign(Source: TPersistent); overrIDe; published property color: Tcolor read Fcolor write Fcolor; property Height: Integer read fheight write fheight; property WIDth : Integer read FWIDth write FWIDth; end; TMyControl = class(TWinControl) private FMyProp : TCustomType; Fcolor1 : Tcolor; Fcolor2 : Tcolor; procedure SetMyProp(AValue: TCustomType); public constructor Create(AOwner: TComponent); overrIDe; destructor Destroy; overrIDe; published property MyProp : TCustomType read FMyProp write SetMyProp; //Now this property has 3 "sub-propertIEs" (this term does not exist in delphi) property color1 : Tcolor read Fcolor1 write Fcolor1; property color2 : Tcolor read Fcolor2 write Fcolor2; end; procedure TCustomType.Assign(Source: TPersistent); var Src: TCustomType; begin if Source is TCustomType then begin Src := TCustomType(Source); Fcolor := Src.color; Height := Src.Height; FWIDth := Src.WIDth; end else inherited; end; constructor TMyControl.Create(AOwner: TComponent); begin inherited; FMyProp := TCustomType.Create; end; destructor TMyControl.Destroy; begin FMyProp.Free; inherited; end; procedure TMyControl.SetMyProp(AValue: TCustomType); begin FMyProp.Assign(AValue); end;总结
以上是内存溢出为你收集整理的delphi – 如何使用子属性编写属性?全部内容,希望文章能够帮你解决delphi – 如何使用子属性编写属性?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)