如下代码:自定义控件的一个属性,希望把几个属性集中到一个条目下
点击前面的加号后,展开其内部的属性。
下面的程序,运行后在属性列表内有
+visibility,但是点击后下面没有内容,为什么?
——————————————————————————————————————————————————————
——————————————————————————————————————————————————————
unit SDProperty;interface
uses SysUtils, Classes;
type Tvisibility=class(Tobject)
  private
    FVisible:boolean;
    FVFrom:integer;
    FVTo:integer;
    procedure setvisible(value:boolean);
    procedure setVFrom(value:integer);
    procedure setVTo(value:integer);
  protected
  public
    constructor create;
    destructor destroy; override;
  published
    property Visible:boolean read Fvisible write setvisible default true;
    property VFrom:integer read FVFrom write setVFrom default 0;
    property VTo:integer read FVTo write setVTo default 0;   end;
//procedure Register;
Implementation
constructor TVisibility.create;
begin
  Fvisible:=true;
  FVFrom:=0;
  FVTo:=0;
end;
destructor TVisibility.destroy;
begin
  inherited;
end;
procedure TVisibility.setvisible(value:boolean);
begin
  FVisible:=value;
end;
procedure Tvisibility.setVFrom(value:integer);
begin
  FVFrom:=value;
end;
procedure TVisibility.setVTo(value:integer);
begin
  FVTo:=value;
end;
end.

解决方案 »

  1.   

    TExPro = class(TPersistent)
     private
        FVisible:boolean;
        FVFrom:integer;
        FVTo:integer;
        procedure setvisible(value:boolean);
        procedure setVFrom(value:integer);
        procedure setVTo(value:integer);
      published
        property Visible:boolean read Fvisible write setvisible default true;
        property VFrom:integer read FVFrom write setVFrom default 0;
        property VTo:integer read FVTo write setVTo default 0;
      end; 
    Tvisibility=class(Tobject) 
    private
      FMyPro: TExPro;
      procedure SetProperties(const Value: TExPro);
    published
        property MyPro:TExPro read FMyPro Write SetProperties;
    end;大致是这样,看一下控件源码吧
      

  2.   

    Tvisibility=class(Tobject)  //这里应该是Tvisibility=class(TComponent)吧
    private
        FMyPro:   TExPro;
        procedure   SetProperties(const   Value:   TExPro);
    published
            property   MyPro:TExPro   read   FMyPro   Write   SetProperties;
    //如果你不希望和TExPro的对象组合你应该这样
    property   MyPro:TExPro   read   FMyPro 
    并且一定要在constructor里面创建,在destructor里面销毁。

    end; 
      

  3.   

    上面两位老兄的回复没有看懂。
    再说一下我的问题:
    给控件增加一条属性,只要把一个属性字段放在published里面注明property,找到read 和write的方法就行了。
    我想把几个属性集中在一个属性下面,点击这个属性前面的+号时,属性展开,可以查看设置子属性。
    看delphi里Tpen,Tbrush,TFont,是这样的效果。看了半天,好像是这个类下面有好几条纪录,这几个类下面都是有定义handle。就不懂了。
    不是很懂。谁可以用自定义的类实现以下,谢谢了
      

  4.   

    明白了。
    我的问题是:自定义的属性类没有create,和free。
    正如smallhand提及的。
    我的属性类定义的已经很完整了,主要就是要在控件的create和destroy内把属性类给create出来。
    是不是实例化呢?