Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Collections
Message
 
 
To
28/07/2003 12:00:05
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00814153
Message ID:
00814171
Views:
16
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform