楼上的,参考一下TCollection和TCollectionItem的写发。类似的代码很容易写的。我帖一段你看看:
TCustomElementItem = class(TCollectionItem)
private
FChecked: Boolean;
FTagId: Integer;
FTagIndex: Integer;
...
published
property Checked: Boolean read FChecked write SetChecked;
property TagId: Integer read GetTagId write SetTagId;
property TagIndex: Integer read GetTagIndex write SetTagIndex;
end;
TCustomElements = class(TOwnedCollection)
private
function GetItem(Index: Integer): TCustomElementItem;
procedure SetItem(Index: Integer
const Value: TCustomElementItem);
protected
procedure NotifyChange;
public
function Add(AComponent: TCustomTemplateComponent): TCustomElementItem;
property Items[Index: Integer]: TCustomElementItem read GetItem write SetItem
default;
end;
TImageElementItem = class(TCustomElementItem)
private
FNewImageFilePath: string;
procedure SetNewImageFilePath(const Value: string);
published
function GetAllowFileExtention: string;
property NewImageFilePath: string read FNewImageFilePath
write SetNewImageFilePath;
end;
TImageElements = class(TCustomElements)
private
function GetItem(Index: Integer): TImageElementItem;
procedure SetItem(Index: Integer
const Value: TImageElementItem);
public
constructor Create(AOwner: TPersistent)
reintroduce;
function Add(AComponent: TImgTemplateComponent): TImageElementItem;
property Items[Index: Integer]: TImageElementItem read GetItem write SetItem
default;
end;
{ TCustomElements }
function TCustomElements.Add(AComponent: TCustomTemplateComponent):
TCustomElementItem;
begin
Result := TCustomElementItem(inherited Add);
...
Result.TagId := AComponent.TagId;
Result.TagIndex := AComponent.TagIndex;
...
end;
function TCustomElements.GetItem(Index: Integer): TCustomElementItem;
begin
Result := TCustomElementItem(inherited GetItem(index));
end;
procedure TCustomElements.SetItem(Index: Integer;
const Value: TCustomElementItem);
begin
inherited SetItem(Index, Value);
end;
{ TImageElements }
constructor TImageElements.Create(AOwner: TPersistent);
begin
inherited Create(AOwner, TImageElementItem);
end;
function TImageElements.Add(AComponent: TImgTemplateComponent):
TImageElementItem;
begin
Result := TImageElementItem(inherited Add(AComponent));
end;
function TImageElements.GetItem(Index: Integer): TImageElementItem;
begin
Result := TImageElementItem(inherited GetItem(Index));
end;
procedure TImageElements.SetItem(Index: Integer;
const Value: TImageElementItem);
begin
inherited SetItem(Index, Value);
end;