[REBOL] Re: Compose iterated fields with different names for each
From: brett:codeconscious at: 12-Jan-2002 0:26
Hi Philippe,
I have made a working example of code similar to yours:
inform-disp: copy []
for e 1 6 1 [
text: join "text" e
coor: to-pair reduce [70 * e + 243 107]
append inform-disp compose [
at (coor) (to-set-word join 'fldmodif e) field 40x22 (text)
]
]
view layout inform-disp
But you wrote that some fields may/may not be created. So how will you know
which exists or not? Here is an example (not good though - read below):
inform-disp: copy []
for e 1 6 1 [
text: join "text" e
coor: to-pair reduce [70 * e + 243 107]
if not equal? 1 random 4 [
append inform-disp compose [
at (coor) (to-set-word join 'fldmodif e) field 40x22 (text)
]
]
]
append inform-disp [
at 10x120
button "Print fields" [
for e 1 6 1 [
if value? fld-name: to-word join 'fldmodif e [
fld: get fld-name
print fld/text
]
]
]
]
view layout inform-disp
There is a problem with this. The fldmodif1, fldmodif2... words are global.
So if you run the code again in the same
session you will not get the correct results.
Here is another way. This way does not use field names - it uses a field
called "TAG" that every face has. You can put
any value you want into tag. In this example I create a new field type
called special-fld. It has an action that will print
the field that was just changed.
inform-disp: copy [
style special-fld field 40x22 [
print [
"Field" face/tag
"at position" face/offset
" has value" mold value
]
]
text "type in the fields"
]
for e 1 6 1 [
text: join "text" e
coor: to-pair reduce [70 * e + 243 107]
append inform-disp probe compose/deep [
at (coor) special-fld with [tag: (e)] (text)
]
]
view layout inform-disp
Hope it helps you.
Brett.