最好给实例!

解决方案 »

  1.   

    你在这个组件的OnCreate事件中写代码创建它,在OnDestroy事件中Free掉它。如:private
      aList:TStringList;
    Published
      Property FaList Read aList Write aList;Public
      Procedure Create(AOwner:TObject);override;Implementation
    procedure Create(AOwner:TObject);
    begin
      aList:=TStringList.Create(Self);
    end;
      

  2.   

    补充纠正一下楼上:
    TMyClass = class(URCLASS)
    private
      FSubList:TList;
    Published
      Property SubList: TList Read FSubList Write FSubList;
    Public
      //构造函数
      Contructor Create(AOwner:TComponent);
      //析构函数
      Destructor Destroy;override;
      //在list里增加自定义的类(TSubClass)
      function AddSubClass: TSubClass;
      
    Implementation
    Constructor TMyClass.Create(AOwner:TComponent);
    begin
      inherited Create(AOwner);
      FSubList := TList.Create;
    end;function TMyClass.AddSubClass: TSubClass;
    begin
      Result := TSubClass.Create;
      ...
      FSubList.Add(Result);
    end;Destructor TMyClass.Destroy;override;
    begin
      //释放list内元素
      while FSubList.Count > 0 do
      begin
        TSubClass(FSubList[0]).Free;
        FSubList.Delete(0);
      end;
      FSubList.Free;
      inherited;
    end;