我制作了一个控件:就是 Panel里面加入一个Label,新控件从TPanel继承,
我在新控件中加入了一个TLabel对象的属性到Published,如下:
FLabel0:TLabel;
property Label0 : TLabel read FLabel0 write FLabel0;
通过该属性,用户可以在设计时更改Label的一些属性,
但是现在的问题是,设置Label属性,运行时没有效果。

解决方案 »

  1.   

    TNewPanel = class(TPanel)
    private
      FLabel : TLanLabel;
    ...
    //需要这样定义
    property LabelColor:TColor read GetLabelColor write SetLabelColor;
     
    function TNewPanel.GetLabelColor:TColor;
    begin
     Result := FLabel.Color;
    end;procedure TNewPanel.SetLabelColor(Value:TColor);
    begin
     FLabel.Color := Value;
    end;constructor TNewPanel.Create(AOwner: TComponent);
    begin
     Inherited Create(AOwner);
     FLabel := TLanLabel.Create(Self);
     FLabel.Parent := Self;
    ...destructor TNewPanel.Destroy;
    begin
     FLabel.Free;
     Inherited;
    end;
      

  2.   

    非常感谢 operfume(橘子香水) ,你说的这种方法一次只能改变Label的一种属性(就是做的里面的Label的Color)但是我想做的是能改变Label的所有属性,就像一遍空间中的Font对象一样,可以改变Font对象的所有属性。求救啊,我一直在线等呢!
      

  3.   

    还有这种做法,我没有试过。你就换个角度解决问了,象上面兄弟说的那有,并不是每个属性你都要改动的,按道理就只有几个常用的属性需要你去改动,没有必要象那有做。
    还有就是你修改的内容必须用内部变量保存在显示的时候重新加载,比如在OnPaint事件中进行加载。
      

  4.   

    谢谢  Blakhawk(黑鹰) 那我的那种情况能够实现吗,属性中不是可以定义对象这种方式吗?