容器集合之TCollection 和 TCollectionItem

本文介绍了 Delphi 中的 TCollection 和 TCollectionItem 类,详细解释了它们的属性和方法,并列举了多种实际应用案例,如 TClientDataSet、TDBGrid 和 TService 等组件中的使用。

TCollection继承于: TObject--TPersistent, 存储TCollectionItem对象的容器.

TCollectionItem继承于: TObject--TPersistent, 表示集合中一个Item.

他们的子类具有对应的关系,如下图所示:

集合类(Tcollection)对应的Item类(TCollectionItem)相关的组件Component
TAggregatesTAggregateTClientDataSet
TCookieCollectionTCookieTWebResponse
TCoolBandsTCoolBandTCoolBar
TDBGridColumnsTColumnTDBGrid
TDependenciesTDependencyTService
TDisplayDimsTDisplayDimTDecisionGrid
TFieldDefsTFieldDefTDataSet
THeaderSectionsTHeaderSectionTHeaderControl
TIndexDefsTIndexDefTTable
TListColumnsTListColumnTListView
TParamsTParammany datasets
TStatusPanelsTStatusPanelTStatusBar
TWorkAreasTWorkAreaTListView

 

(一) 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所属的集合;

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值