有关于DELPHI的TCOLLECTION及TCOLLECTIONITEM类的使用??

morphia 2001-07-30 10:24:44
下面是一个完整的控件单元的代码,可以安装至DELPHI中。
但是!有一个很重要的问题出现了,在Test控件中的TTestCollection
属性可以点开,但是在TTestCollectionItem对象中的TTestSubCollection
属性却点不开了,难道TCollection不可以套用吗?还是我的类写得不正确?

能够解决这些问题的人快快回答我吧,我先谢谢了。 (分数可以再加,谢谢)

unit Test;

interface

uses
Classes;

type
TTestSubCollectionItem = class(TCollectionItem)
private
FProp004: Integer;
FProp003: string;
procedure SetProp003(const Value: string);
procedure SetProp004(const Value: Integer);
published
property Prop003: string read FProp003 write SetProp003;
property Prop004: Integer read FProp004 write SetProp004;
end;

TTestSubCollection = class(TCollection)

end;

TTestCollectionItem = class(TCollectionItem)
private
FProp02: Integer;
FProp01: string;
FSubCollection: TTestSubCollection;
procedure SetProp01(const Value: string);
procedure SetProp02(const Value: Integer);
procedure SetSubCollection(const Value: TTestSubCollection);
public
constructor Create(Collection: TCollection); override;
published
property Prop01: string read FProp01 write SetProp01;
property Prop02: Integer read FProp02 write SetProp02;
property SubCollection: TTestSubCollection read FSubCollection write SetSubCollection;
end;

TTestCollection = class(TCollection)

end;

TTest = class(TComponent)
private
FTestCollection: TTestCollection;
procedure SetTestCollection(const Value: TTestCollection);
public
constructor Create(AOwner: TComponent); override;
published
property TestCollection: TTestCollection read FTestCollection write SetTestCollection;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Test', [TTest]);
end;

{ TTestCollectionItem }

constructor TTestCollectionItem.Create(Collection: TCollection);
begin
inherited Create(Collection);
FSubCollection := TTestSubCollection.Create(TTestSubCollectionItem);
end;

procedure TTestCollectionItem.SetProp01(const Value: string);
begin
FProp01 := Value;
end;

procedure TTestCollectionItem.SetProp02(const Value: Integer);
begin
FProp02 := Value;
end;

procedure TTestCollectionItem.SetSubCollection(
const Value: TTestSubCollection);
begin
FSubCollection.Assign(Value);
end;

{ TTest }

constructor TTest.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTestCollection := TTestCollection.Create(TTestCollectionItem);
end;

procedure TTest.SetTestCollection(const Value: TTestCollection);
begin
FTestCollection.Assign(Value);
end;

{ TTestSubCollectionItem }

procedure TTestSubCollectionItem.SetProp003(const Value: string);
begin
FProp003 := Value;
end;

procedure TTestSubCollectionItem.SetProp004(const Value: Integer);
begin
FProp004 := Value;
end;

end.
...全文
497 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
skt985 2002-01-11
  • 打赏
  • 举报
回复
31530关注! :)
ExitWindows 2001-07-31
  • 打赏
  • 举报
回复
up
morphia 2001-07-31
  • 打赏
  • 举报
回复
啊,已经解决,GETOWNER方法一定要覆盖,呵呵,高兴死了,谢谢谢谢谢谢谢谢!

给victorchen_2000分喽
morphia 2001-07-31
  • 打赏
  • 举报
回复
这个跟定义无关吧,TCOLLECTION本身就可以了,不需要覆盖任何PROTECTED方法,它只是
需要在CREATE的时候代入它管理的ITEM的类类型就应该可以运作,但是,为什么第一层的
COLLECTION可以运行,但是第二层的COLLECTION不可以运行呢???

高手,在哪?????

已经加了3分了,只有这么多可以加,到了明天再加3分!
victorchen_2000 2001-07-31
  • 打赏
  • 举报
回复
没有定义完整!
TTestSubCollection = class(TCollection)
TTestCollection = class(TCollection)
你可以看看src\vcl下的pas 文件,其中有StatusBar的原码。

morphia 2001-07-31
  • 打赏
  • 举报
回复
up
morphia 2001-07-31
  • 打赏
  • 举报
回复
up
morphia 2001-07-30
  • 打赏
  • 举报
回复
拜托拜托,求求回答!!!!!!!!!!!!!

谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢谢!!!

5,928

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧