아래에두 올렸는데....
그건 소스를 다올린거구..이번에는 TCollection생성하는 부분만 따루 테스트 하는
소스를 올립니다...(인터넷에서 찾은거예요...)
파일두개중에 ExpandingComponent.pas가 SubProperty로 TCollection을
생성하는 부분이구요...
OurCollection.pas가 그냥 Property를 생성하는 부분이예요...
그런데 그냥 Property는 TCollection에 생성이 되어 보여지는데...
SubProperty가 생성은 되는거 같은데 Property를 선택했을때 보여지지가 않네요
SubProperty를 보여지게 하는 방법이 뭔가요.....알려주세요...
ExpandingComponent.pas
unit ExpandingComponent;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OurCollection;
type
TExpandingRecord = class(TPersistent)
private
FIntegerProp : Integer;
FStringProp : String;
FCollectionProp : TOurCollection;
procedure SetCollectionProp(const Value: TOurCollection);
public
constructor Create(AOwner : TComponent);
destructor Destroy; override;
procedure Assign(Source : TPersistent); override;
published
property IntegerProp : Integer
read FIntegerProp
write FIntegerProp;
property StringProp : String
read FStringProp
write FStringProp;
property CollectionProp : TOurCollection
read FCollectionProp
write SetCollectionProp;
end;
TExpandingComponent = class(TComponent)
private
{ Private declarations }
FProperty1,
FProperty2,
FProperty3 : TExpandingRecord;
protected
{ Protected declarations }
procedure SetProperty1(const Value : TExpandingRecord);
procedure SetProperty2(const Value : TExpandingRecord);
procedure SetProperty3(const Value : TExpandingRecord);
public
{ Public declarations }
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property Property1 : TExpandingRecord
read FProperty1
write SetProperty1;
property Property2 : TExpandingRecord
read FProperty2
write SetProperty2;
property Property3 : TExpandingRecord
read FProperty3
write SetProperty3;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Article', [TExpandingComponent]);
end;
{ TExpandingRecord }
procedure TExpandingRecord.Assign(Source: TPersistent);
begin
if Source is TExpandingRecord then
with TExpandingRecord(Source) do begin
Self.IntegerProp := IntegerProp;
Self.StringProp := StringProp;
Self.CollectionProp := CollectionProp; //This actually assigns
end else
inherited; //raises an exception
end;
constructor TExpandingRecord.Create(AOwner : TComponent);
begin
inherited Create;
FCollectionProp := TOurCollection.Create(AOwner);
end;
destructor TExpandingRecord.Destroy;
begin
FCollectionProp.Free;
inherited;
end;
procedure TExpandingRecord.SetCollectionProp(const Value: TOurCollection);
begin
FCollectionProp.Assign(Value);
end;
{ TExpandingComponent }
constructor TExpandingComponent.Create(AOwner: TComponent);
begin
inherited;
FProperty1 := TExpandingRecord.Create(Self);
FProperty2 := TExpandingRecord.Create(Self);
FProperty3 := TExpandingRecord.Create(Self);
end;
destructor TExpandingComponent.Destroy;
begin
FProperty1.Free;
FProperty2.Free;
FProperty3.Free;
inherited;
end;
procedure TExpandingComponent.SetProperty1(const Value: TExpandingRecord);
begin
FProperty1.Assign(Value);
end;
procedure TExpandingComponent.SetProperty2(const Value: TExpandingRecord);
begin
FProperty2.Assign(Value);
end;
procedure TExpandingComponent.SetProperty3(const Value: TExpandingRecord);
begin
FProperty3.Assign(Value);
end;
end.
OurCollection.pas
unit OurCollection;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TOurCollectionItem = class(TCollectionItem)
private
FSomeValue : String;
protected
function GetDisplayName : String; override;
public
procedure Assign(Source: TPersistent); override;
published
property SomeValue : String
read FSomeValue
write FSomeValue;
end;
TOurCollection = class(TCollection)
private
{ Private declarations }
FOwner : TComponent;
protected
{ Protected declarations }
function GetOwner : TPersistent; override;
function GetItem(Index: Integer): TOurCollectionItem;
procedure SetItem(Index: Integer; Value: TOurCollectionItem);
procedure Update(Item: TOurCollectionItem);
public
{ Public declarations }
constructor Create(AOwner : TComponent);
function Add : TOurCollectionItem;
function Insert(Index: Integer): TOurCollectionItem;
property Items[Index: Integer]: TOurCollectionItem
read GetItem
write SetItem;
published
{ Published declarations }
end;
TCollectionComponent = class(TComponent)
private
FOurCollection : TOurCollection;
procedure SetOurCollection(const Value: TOurCollection);
protected
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
published
property OurCollection : TOurCollection
read FOurCollection
write SetOurCollection;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Article', [TCollectionComponent]);
end;
{ TOurCollectionItem }
procedure TOurCollectionItem.Assign(Source: TPersistent);
begin
if Source is TOurCollectionItem then
SomeValue := TOurCollectionItem(Source).SomeValue
else
inherited; //raises an exception
end;
function TOurCollectionItem.GetDisplayName: String;
begin
Result := Format('Item %d',[Index]);
end;
{ TOurCollection }
function TOurCollection.Add: TOurCollectionItem;
begin
Result := TOurCollectionItem(inherited Add);
end;
constructor TOurCollection.Create(AOwner: TComponent);
begin
inherited Create(TOurCollectionItem);
FOwner := AOwner;
end;
function TOurCollection.GetItem(Index: Integer): TOurCollectionItem;
begin
Result := TOurCollectionItem(inherited GetItem(Index));
end;
function TOurCollection.GetOwner: TPersistent;
begin
Result := FOwner;
end;
function TOurCollection.Insert(Index: Integer): TOurCollectionItem;
begin
// Result := TOurCollectionItem(inherited Insert(Index));
end;
procedure TOurCollection.SetItem(Index: Integer; Value: TOurCollectionItem);
begin
inherited SetItem(Index, Value);
end;
procedure TOurCollection.Update(Item: TOurCollectionItem);
begin
inherited Update(Item);
end;
{ TCollectionComponent }
constructor TCollectionComponent.Create(AOwner: TComponent);
begin
inherited;
FOurCollection := TOurCollection.Create(Self);
end;
destructor TCollectionComponent.Destroy;
begin
FOurCollection.Free;
inherited;
end;
procedure TCollectionComponent.SetOurCollection(
const Value: TOurCollection);
begin
FOurCollection.Assign(Value);
end;
end.