Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Collections
Message
 
 
À
28/07/2003 12:00:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00814153
Message ID:
00814171
Vues:
17
>How come I can't change a collections key value after the add. It would seem this would be a key feature of the collection object.
>
>
>  lo_collection = NEWOBJECT('Collection')
>  lo_Collection.Add('item','key')
>  ? lo_collection.Item('key') && Prints 'item'
>  lo_collection.Item('key') = "Newitem"
>
>this last line gives error message "Function argument value, type, or count is invalid." Is there a different way to change the collection key's value?

Chuck,
Once added, collection objects themselves are read-only. If the collection object is an object
reference then you can change the values of the object's properties, but not the object itself. You
can add an Update method to your collection class that will handle the updates using intrinsic
Collection methods.
Ex.
loCol.Update('key','Newitem')

define class mycollection as Collection
procedure Update
lparameters teKey, tuvalue
do case
    case vartype(teKey) = 'C'
        local lnpos
        lnpos = THIS.GetKey(teKey)
        if lnpos <> 0 then
            THIS.Remove(teKey)
            THIS.Add(tuvalue,,lnpos)
        endif
    case vartype(tekey) $ 'YNIB'
        if teKey >= 1 and teKey <= THIS.Count then
            THIS.Remove(teKey)
            THIS.Add(tuvalue,,teKey)
        endif
    otherwise
        * what were you thinking; don't do anything
endcase
endproc
enddefine
HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform