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

[REBOL] Re: getting dynamically to object word ...

From: joel:neely:fedex at: 23-Jan-2003 9:51

Hi, Petr, How about an alternative...? Petr Krenzelok wrote:
> Hi, > > let's suppose I have dynamically generated UI ... now I need to > create some function to iterate thru UI elements and get their > values. I found following way works, but I have two questions ... > > for i 1 7 1 [for j 0 4 1 [print do join 'fld [i j "/text"]]] > > I simply have fld10, fld12, fld13, fld14 .... fld74 ... > > 1) Is it safe to use 'do? > 2) Is there any other way of how to dynamically compose name of already > existing object and get to its words using 'in? >
Instead of dynamically composing the name of an existing object, why not add the object to a collection (e.g. block) at the point of its creation? Then you can simply iterate over the collection, calling whatever method(s) you need for any purpose. I've had *VERY* little time with /View (still waiting for the MacOS/X version...) but did use that technique in a couple of little demos I wrote early on. (Please forgive any stylistic ugliness or cut&paste goofs! ;-) A simplified version of the relevant portions would look something like this: btnArray: copy [] ... btnX: none uiSpec: [ style xbtn button 20x20 "x" goodColor [flipLeft face/user-data] ... btnX: xbtn user-data 1 do [append btnArray btnX] btnX: xbtn user-data 2 do [append btnArray btnX] ... btnX: xbtn user-data 10 do [append btnArray btnX] ... ] ui: layout uiSpec run: func [ ] [ repeat btnX 10 [ setBtnArrayText btnX ] view ui ] The net effect is that btnArray holds all of the button objects, so that other functions/methods (e.g. setBtnArrayText) can access the buttons at any time. IMHO this has advantages over dynamically composed source/names for the following reasons: 1) no scope worries 2) faster 3) fewer opportunities for breakage (fewer moving parts) -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446