容器集合之TCollection 和 TCollectionItem

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Elite Container是DELPHI下的一个轻量级IoC对象容器(IoC:Inverse of Control,反转控制)。它是参考了Java中的Spring框架(主要是配置文件的写法),并结合DELPHI的特点来构建的。相比Spring的对象容器,它提供的功能更为精简常用(如对象延迟创建、对象属性自动注入等),降低了学习的难度,并且提供了很多扩展点,你只需简单地写一个插件实现类,并在配置文件中进行简单配置,就可以让Elite Container拥有你的自定义功能! 借助Elite Container和Ioc思想,你可以更轻易地构建出具有松散耦合、重用度高的应用程序。它的核心思想就是拆分功能的接口和实现,上层只依赖于下层的接口,然后通过Elite Container的配置,把不同的实现类注入到该接口中,达到更换功能,也就是复用已有代码的目的。设计人员可以真正地发挥好自己的面向对象思想和相关设计模式,来架构企业级的应用程序,而无需象以前那样,在Delphi中用起面向对象总有点捉襟见袖的感觉。 ps. 由于写程序,还有精心准备的26个例子,都花费了我很多的时间,所以象征性地收2个资源分,希望大家不会介意:) ps2. 说明一下,开发出来的程序在发布的时候,除了发布EliteCore.bpl、EliteContainer.bpl外,还需要发布rtl.bpl(EliteCore.bpl引用到了它)。由于一时疏忽,例子中的Bin目录里忘记带上它了,请大家注意,谢谢~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值