|
storing lists in handlers on the fly
At 21:04 16.03.98 +0100, adflores wrote:
>HEllo,
>
>Is it possible to affect a list to a member (a field member)?
>How ?
>
Pardon,
do you want to store a list in a field and retrieve it later?
If the list is smaller than 31k all you need is
set the text of member "myField" = string(myList)
set myList = value(the text of member "myField")
But this fails if <VOID>, RETURN or QUOTE is contained somewhere in the list.
value(StringOftheList) will return <void> then. An alternative is to create a
handler that returns a list on the fly.
on returnList me
return [ #item1, #item2, #item3 ]
end
This may be limited to store smaller lists since there is a maximum to the
length of a single lingo line. It gets hard to read anyway. Below is a handler
that transforms a property list to scripttext which in turn returns the
original list when called.
i.e.
set LpTest=[#a:1,#b:2,#c:3]
put lp2lingo(Lptest,"returnMyList")
-- "
on returnMyList
set dLp=[:]
setaProp dLp,#a,1
setaProp dLp,#b,2
setaProp dLp,#c,3
return dLp
end "
If you create a new #script member and set its scripttext to this functions
result you can store the content of a list in a member in a way that is open
for editing.
-- movie script
on lp2lingo dLp, dHandlerName
-- transform a propListe into scripttext
-- of a function which returns that propList
set dTxt = RETURN
set dTxt = dTxt & " on " & string(dHandlername) & RETURN
set dTxt = dTxt & "set dLp=[:]" & RETURN
set dLp.Anz = Count(dLp)
repeat with rum=1 to dLp.Anz
set dProp = getPropAt(dLp,rum)
set dVal = getat(dLp,rum)
-- #symbol, #string need some special formatting
set dProp = formatVal2String(dProp)
set dVal = formatVal2String(dVal)
set dLine= "setaProp dLp," & dProp & "," & dVal
set dTxt = dTxt & " " & dLine & RETURN
end repeat
set dTxt = dTxt & " " & "return dLp" & RETURN
set dTxt = dTxt & "end "
return dTxt
end
on formatVal2String dVal
-- save #symbol and #string
set dTxt=""
set dIlk = ilk(dVal)
case dIlk of
#symbol:
set dTxt = "#" & string(dVal)
#string:
set dTxt = QUOTE & string(dVal) & QUOTE
otherwise
set dTxt = string(dVal)
end case
return dtxt
end
Best regards
Daniel Plaenitz
|