************************************************** *-- Class Library: e:\my work\foxpro\projects\common\classes\collection.vcx ************************************************** ************************************************** *-- Class: gkkcollection (e:\my work\foxpro\projects\common\classes\collection.vcx) *-- ParentClass: label *-- BaseClass: label *-- Time Stamp: 12/19/13 01:20:09 PM * * DEFINE CLASS gkkcollection AS label AutoSize = .T. Caption = "GKKCollection" Height = 17 Visible = .F. Width = 82 *-- XML Metadata for customizable properties _memberdata = [<VFPData><memberdata name="count" type="property" display="Count"/><memberdata name="itemkey" type="property" display="ItemKey"/><memberdata name="items" type="property" display="Items"/><memberdata name="add" type="method" display="Add"/><memberdata name="getitem" type="method" display="GetItem"/><memberdata name="remove" type="method" display="Remove"/><memberdata name="removeall" type="method" display="RemoveAll"/><memberdata name="setkey" type="method" display="SetKey"/><memberdata name="getitemkey" type="method" display="GetItemKey"/></VFPData>] *-- Count of items in the collection ***Integer count = 0 Name = "gkkcollection" *-- Key of the item added to the collection HIDDEN itemkey[1] *-- List of Items in collection DIMENSION items[1] *-- Adds items to the collection PROCEDURE add LPARAMETERS txItem, tcKey LOCAL lnNdx IF VARTYPE(tcKey) != "C" tcKey = TRANSFORM(tcKey) ENDIF lnNdx = ASCAN(this.ItemKey, tcKey, 1, this.Count, 1, 15) IF lnNdx > 0 this.Items[lnNdx] = txItem ELSE this.Count = this.Count + 1 DIMENSION this.ItemKey[this.Count], this.Items[this.Count] this.ItemKey[this.Count] = UPPER(tcKey) this.Items[this.Count] = txItem ENDIF ENDPROC *-- Returns the requested Item index from key PROCEDURE getitem LPARAMETERS tcItemKey LOCAL lnIndex, lnItem lnIndex = 0 IF VARTYPE(tcItemKey) != "C" tcItemKey = TRANSFORM(tcItemKey) ENDIF FOR lnItem=1 TO this.Count IF this.ItemKey[lnItem] == UPPER(tcItemKey) lnIndex = lnItem EXIT ENDIF ENDFOR RETURN lnIndex ENDPROC *-- Removes selected item from the collection PROCEDURE remove LPARAMETERS txItem IF VARTYPE(txItem) = "N" ADEL(this.Items, txItem) ADEL(this.ItemKey, txItem) this.Count = this.Count - 1 ELSE FOR lnItem=1 TO this.Count IF this.ItemKey[lnItem] == UPPER(txItem) ADEL(this.Items, lnItem) ADEL(this.ItemKey, lnItem) this.Count = this.Count - 1 EXIT ENDIF ENDFOR ENDIF IF this.Count > 0 DIMENSION this.ItemKey[this.Count], this.Items[this.Count] ELSE DIMENSION this.ItemKey[1], this.Items[1] ENDIF ENDPROC *-- Removes all items from the collection PROCEDURE removeall this.Count = 0 DIMENSION this.ItemKey[1], this.Items[1] this.ItemKey[1] = .NULL. this.Items[1] = .NULL. ENDPROC *-- Sets the item key value PROCEDURE setkey LPARAMETERS tnItem, tcKey IF BETWEEN(tnItem, 1, this.Count) this.ItemKey[tnItem] = UPPER(tcKey) ENDIF ENDPROC *-- Returns the key for the selected item index PROCEDURE getitemkey LPARAMETERS tnItem IF VARTYPE(tnItem) = "N" RETURN this.ItemKey[tnItem] ELSE RETURN "" ENDIF ENDPROC ENDDEFINE * *-- EndDefine: gkkcollection **************************************************