Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Compose iterated fields with different names for each

 [1/6] from: info::id-net::ch at: 11-Jan-2002 10:50


I composed a part of a layout with different fields. Those fields are produced if a condition is true. So that's why I want a name for each of them. The names should be fldmodif1, fldmodif2, fldmodif3, etc., to see if the user change them when he will press a button. I used the append exemple-layout REDUCE COMPOSE/DEEP to make it in a boucle of 'for. Like that : for e 1 6 1 [ text8: join first tran ["-" ghi] coor: 243 + (70 * e) coor: to-pair (join coor "x107") append inform-disp reduce compose/deep ['at (coor) fldmodif1: 'field 40x22 (text8)] ] You noticed that it that example the name is fldmodif1. But i cant, using reduce compose/deep, produce a fldmodif (e) without having an error. I tried to produce a string first and then append it to the inform-box. But it doesnt work too. text567: join "at " [coor " fldmodif" e ": field 40x22 " text8] print text567 append inform-disp reduce compose/deep [(text567)] How can i make it ?? Philippe Oehler

 [2/6] 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.

 [3/6] from: nitsch-lists:netcologne at: 11-Jan-2002 18:56


RE: [REBOL] Re: Compose iterated fields with different names for each Hi Philippe, Brett i like Bretts tag way. an old of me was areas: copy[a1 none a2 none ..] [.. t: area do[areas/a1: t] t: area do[areas/a2: t] .. ] the trick is to copy 't in the do[] somewhere, because here you have full rebol available to index somehow. you get the idea -Volker [brett--codeconscious--com] wrote:

 [4/6] from: info:id-net:ch at: 11-Jan-2002 21:49


Thanks a lot, Brett. That's the kind of response that help me to understand a higher level (the global value of the words).. Could explain me more about the "with" stuff attached with the field ? Is it like the html form ? Philippe

 [5/6] from: brett:codeconscious at: 12-Jan-2002 13:23


Hi Philippe,
> Could explain me more about the "with" stuff attached with the field ? Is
it
> like the html form ?
First I need to correct my earlier post. Not every face has a tag field. I just learnt that I actually created TAG using WITH. Have a look section "6.7. Face Facet Blocks" of the View Developer's guide. It says of "with": "The with block allows you to specify any other type of face characteristic using standard REBOL object format." What this is saying is that WITH allows you to extend the definition of a style for your own purposes. That is, you can add more fields (facets). These fields could contain strings, numbers, functions or any other type of value you want. You can use it in a style definition (probably more useful) or use it like it did, directly on the thing (field, box, etc) you are creating. Some examples. First WITH allows you to set existing fields using the normal Rebol object format: view layout [ box with [color: green] ] Now to extend a style. Here I will add my own field "special-value" (like I did with TAG in my earlier post): view layout [ style named-box box green with [special-value: none] Text "The box has a special value. Press the buttons to set and print it." the-box: named-box button "Set" [the-box/special-value: now] button "Print" [print the-box/special-value] ] I did not realise before now just how powerful this extending feature is. It could be used to help build more sophisticated frameworks or reduce the complexity of your code. For example, when you create styles you can base one style upon another in order to share common features. But what if you are using someone else's styles? Here is a contrived example. Instead of writing: view layout [ box "click me" red [ print ["box has been activated"] ] button "click me" [ print ["button has been activated"] ] ] we can use common code: a-common-action: [ action: func[face value][print [face/style "has been activated"]] ] view layout [ box "click me" red with a-common-action button "click me" with a-common-action ] Cheers Brett.

 [6/6] from: jason:cunliffe:verizon at: 11-Jan-2002 23:42


Brett Handley <[brett--codeconscious--com]> wrote: ...snip..
> I did not realise before now just how powerful this extending feature is.
It
> could be used to help build more sophisticated frameworks or reduce the > complexity of your code.
<<quoted lines omitted: 16>>
> box "click me" red with a-common-action > button "click me" with a-common-action
Brett, Thank you. This is really an interesting discovery and very rebolistic.. As you say, it could really open the door to powerful but readable frameworks. ./Jason

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted