有关于DELPHI的TCOLLECTION及TCOLLECTIONITEM类的使用??
下面是一个完整的控件单元的代码,可以安装至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.