容器集合之TCollection 和 TCollectionItem
TCollection继承于: TObject--TPersistent, 存储TCollectionItem对象的容器. TCollectionItem继承于: TObject--TPersistent, 表示集合中一个Item. 他们的子类具有对应的关系,如下图所示:
(一) TCollection 属性: 1. property Count: Integer; Item 的个数; 只读; 2. property ItemClass: TCollectionItemClass; Item所属的类; 只读; type TCollectionItemClass = class of TCollectionItem; 3. property Items[Index: Integer]: TCollectionItem; 按索引检索对应的 Item. 4. property NextID: Integer; 下一个将要加入集合中的Item的唯一ID; 只读; 5. property PropName: string; 属性名. 6. property UpdateCount: Integer; 调用了 BeginUpdate 而没有对应的调用 EndUpdate 的次数;只读; 方法: 1. function Add: TCollectionItem; 创建一个TCollectionItem实例并加入集合中. 2. procedure Assign(Source: TPersistent); override; 拷贝给另一份集合. 3. procedure BeginUpdate; virtual; 暂停屏幕刷新(加速处理,并避免增减Item时屏幕闪烁),直到 EndUpdate方法调用; 虚方法; 4. procedure Changed; Protected 在EndUpadte之后自动执行,以检查和更新字段内容. 5. procedure Clear; 删除所有的项; 6. procedure Delete(Index: Integer); 删除指定索引的 Item. 7. procedure EndUpdate; virtual; 重新屏幕刷新; 8. function FindItemID(ID: Integer): TCollectionItem; 根据ID检索对应的 Item. 9. function GetNamePath: string; override; 返回设计时使用的名字; 10. function Insert(Index: Integer): TCollectionItem; 插入1个 Item. 11. function Owner: TPersistent; 返回集合的操作者; 12. procedure SetItem(Index:Integer; Value: TCollectionItem); copy 实例到 Index对应的Item中; 13. procedure Update(Item: TCollectionItem); virtual; 自动调用更新; (二) TCollectionItem 属性: 1. property Collection: TCollection; 存放Item 的容器; 2. property DisplayName: string; 集合编辑器的名字; 3. property ID: Integer; Item的 唯一 ID. 4. property Index: Integer; Item在容器中的索引号. 方法: 1. function GetDisplayName: string; virtual; 返回集合编辑器的名称; 2. function GetOwner: TPersistent; override; 返回Item所属的集合; |
|