TCollection繼承于: TObject--TPersistent, 存儲TCollectionItem對象的容器.
TCollectionItem繼承于: TObject--TPersistent, 表示集合中一個Item.
他們的子類具有對應(yīng)的關(guān)系,如下圖所示:
集合類(Tcollection)對應(yīng)的Item類(TCollectionItem)相關(guān)的組件Component
TAggregatesTAggregateTClientDataSet
TCookieCollectionTCookieTWebResponse
TCoolBandsTCoolBandTCoolBar
TDBGridColumnsTColumnTDBGrid
TDependenciesTDependencyTService
TDisplayDimsTDisplayDimTDecisionGrid
TFieldDefsTFieldDefTDataSet
THeaderSectionsTHeaderSectionTHeaderControl
TIndexDefsTIndexDefTTable
TListColumnsTListColumnTListView
TParamsTParammany datasets
TStatusPanelsTStatusPanelTStatusBar
TWorkAreasTWorkAreaTListView
(一) TCollection
屬性:
1. property Count: Integer;
Item 的個數(shù); 只讀;
2. property ItemClass: TCollectionItemClass;
Item所屬的類; 只讀;
type TCollectionItemClass = class of TCollectionItem;
3. property Items[Index: Integer]: TCollectionItem;
按索引檢索對應(yīng)的 Item.
4. property NextID: Integer;
下一個將要加入集合中的Item的唯一ID; 只讀;
5. property PropName: string;
屬性名.
6. property UpdateCount: Integer;
調(diào)用了 BeginUpdate 而沒有對應(yīng)的調(diào)用 EndUpdate 的次數(shù);只讀;
方法:
1. function Add: TCollectionItem;
創(chuàng)建一個TCollectionItem實例并加入集合中.
2. procedure Assign(Source: TPersistent); override;
拷貝給另一份集合.
3. procedure BeginUpdate; virtual;
暫停屏幕刷新(加速處理,并避免增減Item時屏幕閃爍),直到 EndUpdate方法調(diào)用; 虛方法;
4. procedure Changed; Protected
在EndUpadte之后自動執(zhí)行,以檢查和更新字段內(nèi)容.
5. procedure Clear;
刪除所有的項;
6. procedure Delete(Index: Integer);
刪除指定索引的 Item.
7. procedure EndUpdate; virtual;
重新屏幕刷新;
8. function FindItemID(ID: Integer): TCollectionItem;
根據(jù)ID檢索對應(yīng)的 Item.
9. function GetNamePath: string; override;
返回設(shè)計時使用的名字;
10. function Insert(Index: Integer): TCollectionItem;
插入1個 Item.
11. function Owner: TPersistent;
返回集合的操作者;
12. procedure SetItem(Index:Integer; Value: TCollectionItem);
copy 實例到 Index對應(yīng)的Item中;
13. procedure Update(Item: TCollectionItem); virtual;
自動調(diào)用更新;
(二) 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所屬的集合;