|
storList
>>I have 128 objects that have complex properties held as nested property
>>lists.
>>
>>I want these objects to retain their property values from one session to
>>another.
>>
>>The problem: no matter how I store the property lists in fields, when I try
>>to birth the objects anew from the fields all the property lists turn into
>>strings,
Rob Dillon wrote
>
>So if you took apart the list based on the properties you'd have 8
>properties and 8 values. If you place each property on a new line in a
>field followed by the value on a new line, you'd have a field with 16
>lines, property,value, property,value, etc. Each of the properties would
>become a string and so would each value.
>
>To keep the properties from becoming text forever more add a #, pound sign,
>in front of each as you move them to the field.
>
>The values would remain intact, they'd just have quotes added at each end.
Hope I'm not missing something important, but why make it so complicated?
Here are two handler that store/retrieve any List to/from a field, as long as
that list contains none of the three: RETURN, QUOTE, <VOID> :
on saveToField dLp,dField
set dStr=string(dLp)
put dStr into field dField
end
on getFromField dField
set dLp=value(field dField)
return dLp
end
and this handler generates Random property lists to test the two above:
on getLpRandom NoItem, depth
if voidP(NoItem) then set NoItem=Random(8)
if voidP(depth) then set depth=2
set dLp=[:]
set LContent=[]
append LContent,[1,"two",#three]
append LContent,Random(200)
append LContent,#Symbol
append LContent,the time
if depth > 1 then append LContent, getLpRandom (NoItem, depth-1)
set LContent.count=Count(LContent)
set t1=[:]
repeat with dCount=1 to NoItem
set dProp=value("#" & "Prop" & string(dCount))
set dVal = getat(LContent,Random(LContent.Count))
addProp dLp,dProp,dVal
end repeat
return dLp
end
i put them all together in a movie script and this is from the message window:
set dLp= getLpRandom(8,2)
saveToField dLp,"pillow"
put getFromField ("pillow")
-- [#Prop1: 1, #Prop2: [1, "two", #three], #Prop3: [1, "two", #three], #Prop4: [1, "two", #three], #Prop5: [#Prop1: #symbol, #Prop2: "02:36 ", #Prop3: 74, #Prop4: "02:36 ", #Prop5: #symbol, #Prop6: [1, "two", #three], #Prop7: #symbol, #Prop8: "02:36 "], #Prop6: #symbol, #Prop7: [1, "two", #three], #Prop8: #symbol]
put dLp
-- [#Prop1: 1, #Prop2: [1, "two", #three], #Prop3: [1, "two", #three], #Prop4: [1, "two", #three], #Prop5: [#Prop1: #symbol, #Prop2: "02:36 ", #Prop3: 74, #Prop4: "02:36 ", #Prop5: #symbol, #Prop6: [1, "two", #three], #Prop7: #symbol, #Prop8: "02:36 "], #Prop6: #symbol, #Prop7: [1, "two", #three], #Prop8: #symbol]
put ilk(getFromField ("pillow"))
-- #propList
put ilk(dLp)
-- #propList
Best regards
Daniel Plaenitz
|