我从未遇到需要它的情况,这是我第一次尝试将var cubes = [
['a', 'b', 'c', 'd', 'e'],
['f', 'g', 'h', 'i', 'j'],
['k', 'l', 'm', 'n', 'o']
];
var flattenStr = cubes[0].reduce((a, c, i1) => a.concat(cubes.map((s, i2) => s[i1])), []).join("");
var output = flattenStr.match(/.{1,5}/g);
console.log( output );
作为另一个TCollection
的{{1}}。
这一切都很好,但是当TCollectionItem
TCollection
属性后面的三个点被点击时,没有反应,即。没有出现包含该子列表的对话框TCollectionItem
。
我的印象是,因为不需要花哨的属性编辑器(子TCollection
只携带具有TCollection
和TCollection
属性的项目),IDE几乎可以自动处理它。
显然情况并非如此,或者我正在监督显而易见的,这是一种长期的痛苦。
实现(运行时)单元具有:
string
single
过程在设计时单元中实现,只调用type
TBitmapItemTag = class(TCollectionItem)
private
FTagName: string;
FTagFloat: Single;
published
property TagName: string read FTagName write FTagName;
property TagFloat: Single read FTagFloat write FTagFloat;
end;
TBitmapItemTags = class(TOwnedCollection)
end;
TBitmapItem = class(TCollectionItem)
private
FBitmap: TBitmap;
FBitmapItemTags: TBitmapItemTags;
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
published
property Bitmap: TBitmap read FBitmap write FBitmap;
property Tags: TBitmapItemTags read FBitmapItemTags write FBitmapItemTags;
end;
TBitmaps = class(TCollection)
end;
TBitmapCollection = class(TComponent)
private
FBitmaps: TBitmaps;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Bitmaps: TBitmaps read FBitmaps write FBitmaps;
end;
implementation
{ TBitmapItem }
constructor TBitmapItem.Create(Collection: TCollection);
begin
inherited Create(Collection);
FBitmap := TBitmap.Create(0, 0);
FBitmapItemTags := TBitmapItemTags.Create(Self,TBitmapItemTag);
end;
destructor TBitmapItem.Destroy;
begin
FBitmap.Free;
FBitmapItemTags.Free;
inherited;
end;
{ TBitmapCollection }
constructor TBitmapCollection.Create(AOwner: TComponent);
begin
inherited;
FBitmaps := TBitmaps.Create(TBitmapItem);
end;
destructor TBitmapCollection.Destroy;
begin
FBitmaps.Free;
inherited;
end;
过程。并且持有一些懒惰的Register
尝试无效。
如果有人能指出最短路径以便IDE识别RegisterComponents
,我将不胜感激。
答案 0 :(得分:2)
您需要将TBitmaps
更改为TOwnedCollection
而不是TCollection
。
我还建议为TBitmapItemTags
和TBitmaps
定义显式构造函数。
您还需要为基于对象的属性添加一些setter方法,否则会冒运行时内存泄漏的风险。您的setter应该在对象上调用Assign()
来将属性值从一个对象复制到另一个对象。 TCollection
已为您实施Assign()
,但您必须在收集项中实施Assign()
。
试试这个:
type
TBitmapItemTag = class(TCollectionItem)
private
FTagName: string;
FTagFloat: Single;
public
procedure Assign(ASource: TPersistent); override;
published
property TagName: string read FTagName write FTagName;
property TagFloat: Single read FTagFloat write FTagFloat;
end;
TBitmapItem = class;
TBitmapItemTags = class(TOwnedCollection)
public
constructor Create(AOwner: TBitmapItem); reintroduce;
end;
TBitmapItem = class(TCollectionItem)
private
FBitmap: TBitmap;
FTags: TBitmapItemTags;
procedure SetBitmap(AValue: TBitmap);
procedure SetTags(AValue: TBitmapItemTags);
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
procedure Assign(ASource: TPersistent); override;
published
property Bitmap: TBitmap read FBitmap write SetBitmap;
property Tags: TBitmapItemTags read FTags write SetTags;
end;
TBitmapCollection = class;
TBitmaps = class(TOwnedCollection)
public
constructor Create(AOwner: TBitmapCollection); reintroduce;
end;
TBitmapCollection = class(TComponent)
private
FBitmaps: TBitmaps;
procedure SetBitmaps(AValue: TBitmaps);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Bitmaps: TBitmaps read FBitmaps write SetBitmaps;
end;
{ TBitmapTagItem }
procedure TBitmapItemTag.Assign(ASource: TPersistent);
begin
if ASource is TBitmapItemTag then
begin
FTagName := TBitmapItemTag(ASource).TagName;
FTagFloat := TBitmapItemTag(ASource).TagFloat;
end
else
inherited;
end;
{ TBitmapItemTags }
constructor TBitmapItemTags.Create(AOwner: TBitmapItem);
begin
inherited Create(AOwner, TBitmapItemTag);
end;
{ TBitmapItem }
constructor TBitmapItem.Create(Collection: TCollection);
begin
inherited Create(Collection);
FBitmap := TBitmap.Create(0, 0);
FTags := TBitmapItemTags.Create(Self);
end;
destructor TBitmapItem.Destroy;
begin
FBitmap.Free;
FTags.Free;
inherited;
end;
procedure TBitmapItem.Assign(ASource: TPersistent);
begin
if ASource is TBitmapItem then
begin
FBitmap.Assign(TBitmapItem(ASource).Bitmap);
FTags.Assign(TBitmapItem(ASource).Tags);
end
else
inherited;
end;
procedure TBitmapItem.SetBitmap(AValue: TBitmap);
begin
FBitmap.Assign(AValue);
end;
procedure TBitmapItem.SetTags(AValue: TBitmapItemTags);
begin
FTags.Assign(AValue);
end;
{ TBitmaps }
constructor TBitmaps.Create(AOwner: TBitmapCollection);
begin
inherited Create(AOwner, TBitmapItem);
end;
{ TBitmapCollection }
constructor TBitmapCollection.Create(AOwner: TComponent);
begin
inherited;
FBitmaps := TBitmaps.Create(Self);
end;
destructor TBitmapCollection.Destroy;
begin
FBitmaps.Free;
inherited;
end;
procedure TBitmapCollection.SetBitmaps(AValue: TBitmaps);
begin
FBitmaps.Assign(AValue);
end;