1. Variable substitution
- Posted by Mike777 <anon4321 at ?m?il.com> Dec 12, 2007
- 525 views
- Last edited Dec 13, 2007
I have read a few threads on variable substitution, but they all seem to predate v3.1.1. Has the ability been added? If not, is there a common way to implement it? I'm trying to develop of database driven windowing system. That means I read from my database the information I need in order to build windows and widgets. A simple example might be that I go to the database to find that I want to build a combo box and that the name of the combo box should be "Combo1". If I was positioning the combo myself in the IDE, it might generate the following: global constant Combo1 = createEx( Combo, "", Window1, 432, 76, 588, 28*6, PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, 0 ) After I read the database, I have two variables, say TYPEOFWIDGETTOBUILD, which has the value "Combo" and NUMBEROFWIDGETTOBUILD, which has the value "1" Is there any way to write something like: global constant &TYPEOFCOMOBOTOBUILD&NAMEOFWIDGETTOBUILD = createEx( Combo, "", Window1, 432, 76, 588, 28*6, PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, 0 ) If that can't be done, can somebody suggest a workaround? Thanks Mike
2. Re: Variable substitution
- Posted by Mike <vulcan at w?n.co?nz> Dec 12, 2007
- 559 views
- Last edited Dec 13, 2007
Mike777 wrote: > > I have read a few threads on variable substitution, but they all seem to > predate > v3.1.1. Has the ability been added? If not, is there a common way to > implement > it? > > I'm trying to develop of database driven windowing system. That means I read > from my database the information I need in order to build windows and widgets. > > A simple example might be that I go to the database to find that I want to > build > a combo box and that the name of the combo box should be "Combo1". > > If I was positioning the combo myself in the IDE, it might generate the > following: > > global constant Combo1 = createEx( Combo, "", Window1, 432, 76, 588, 28*6, > PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, > 0 ) > > After I read the database, I have two variables, say TYPEOFWIDGETTOBUILD, > which > has the value "Combo" and NUMBEROFWIDGETTOBUILD, which has the value "1" > > Is there any way to write something like: > > global constant &TYPEOFCOMOBOTOBUILD&NAMEOFWIDGETTOBUILD = createEx( Combo, > "", Window1, 432, 76, 588, 28*6, PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, 0 ) > > If that can't be done, can somebody suggest a workaround? > > Thanks > > Mike What you seem to be trying to do will entail building a file that contains the correct text. You need to output a text string having the desired values. Eg,
sequence text text = "global constant " & TYPEOFCOMOBOTOBUILD&NUMBEROFWIDGETTOBUILD This (as you know) evaluates to "global constant Combo1" You can use a function like sprintf() to format certain values (such as control dimensions etc..), eg: constant height = 100, width = 200 text = sprintf( "Window, %d, %d" {width, height}) ..becomes "Window, 200, 100" Another example: text = sprintf( "global constant %s%s = create( %s, \"\", Window1, %d, %d)", {TYPEOFCOMOBOTOBUILD, NUMBEROFWIDGETTOBUILD, TYPEOFCOMOBOTOBUILD, width, height} ) text is now "global constant Combo1 = create( Combo, "", Window1, 200, 100)" And then there is printf() which is the same as sprintf() but also outputs the string to a file. If you create the text string separately you can use puts() to output it to a file, eg: puts(file_id, text) Dont forget the line terminator, eg: puts(file_id, text & '\n')
HTH, Mike
3. Re: Variable substitution
- Posted by c.k.lester <euphoric at ck?ester.com> Dec 12, 2007
- 525 views
- Last edited Dec 13, 2007
Mike777 wrote: > > Is there any way to write something like: > > global constant &TYPEOFCOMOBOTOBUILD&NAMEOFWIDGETTOBUILD = createEx( Combo, > "", Window1, 432, 76, 588, 28*6, PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, 0 ) > > If that can't be done, can somebody suggest a workaround? I would just store them in a sequence. Something like this: sequence controls controls = {{},{}} procedure add_control( sequence name, sequence control ) controls[1] = append( controls[1], name ) controls[2] &= createEx( ... ) end procedure function get_control( sequence name ) integer i i = find(name,controls[1]) return controls[2][i] end function I don't think the overhead would be unwieldy on a modern PC. Be sure to investigate Derek's awesome alternate method of creating controls ("newUIObj"). See this: http://www.users.bigpond.com/ddparnell/euphoria/Docs/DEFINING_CONTROL.htm#NEWUIOBJ http://www.users.bigpond.com/ddparnell/euphoria/Docs/EVENT.htm#STARTAPP I think Win32Lib should deprecate the old way. :) The newUIObj functionality is very versatile. You could read whole interface systems from a text file (or database!)... but there's a lot more to it. ********************************************** ****************OMG!!!!!!!!!!***************** ********************************************** Actually, now that I've typed all this up... Looks like the newUIObj feature already has provision for calling named controls... So, either use what I said above with the "old way," or go with the new and improved way. Derek, you really should trumpet newUIObj+startApp. :) I wonder how easy it would be to make the IDE output newUIObjs instead of create()s... :)
4. Re: Variable substitution
- Posted by Mike777 <anon4321 at gmail.?o?> Dec 12, 2007
- 517 views
- Last edited Dec 13, 2007
c.k.lester wrote: > > Mike777 wrote: > > > > Is there any way to write something like: > > > > global constant &TYPEOFCOMOBOTOBUILD&NAMEOFWIDGETTOBUILD = createEx( Combo, > > "", Window1, 432, 76, 588, 28*6, PBS_VERTICAL+LBS_NOINTEGRALHEIGHT, 0 ) > Be sure to investigate Derek's awesome alternate method of creating > controls ("newUIObj"). >.... > The newUIObj functionality is very versatile. You could read whole > interface systems from a text file (or database!)... but there's a lot more > to it. > > ********************************************** > ****************OMG!!!!!!!!!!***************** > ********************************************** > > Actually, now that I've typed all this up... Looks like the newUIObj > feature already has provision for calling named controls... So, either use > what I said above with the "old way," or go with the new and improved way. > > Derek, you really should trumpet newUIObj+startApp. :) > > I wonder how easy it would be to make the IDE output newUIObjs instead of > create()s... :) It appears that newUUIObj is exactly what I'm looking for. Back to the testing bench...... Thanks Mike
5. Re: Variable substitution
- Posted by Mike777 <anon4321 at g?ail.?om> Dec 13, 2007
- 519 views
Mike wrote: > Mike777 wrote: > > > > I have read a few threads on variable substitution, but they all seem to > > predate > > v3.1.1. Has the ability been added? If not, is there a common way to > > implement > > it? > What you seem to be trying to do will entail building a file that contains the > correct text. Thanks for the code, it will be helpful. However, I don't think it will allow me a one-pass solution, will it? Assuming I write the file with a bunch of those lines, how do I then execute those lines within the same program that wrote them? If the goal is to build a separate exw file which can then be run, what you suggest would work a treat, though. Otherwise, I think I'm heading down the newUIOBJ path. Mike
6. Re: Variable substitution
- Posted by Mike <vulcan at w?n.co.n?> Dec 13, 2007
- 535 views
Mike777 wrote: > > Mike wrote: > > > Mike777 wrote: > > > > > > I have read a few threads on variable substitution, but they all seem to > > > predate > > > v3.1.1. Has the ability been added? If not, is there a common way to > > > implement > > > it? > > > What you seem to be trying to do will entail building a file that contains > > the > > correct text. > > Thanks for the code, it will be helpful. However, I don't think it will allow > me a one-pass solution, will it? Assuming I write the file with a bunch of > those lines, how do I then execute those lines within the same program that > wrote them? > > If the goal is to build a separate exw file which can then be run, what you > suggest would work a treat, though. > > Otherwise, I think I'm heading down the newUIOBJ path. > > Mike To run an external file you would use system() or system_exec(). I use the latter in Orac to execute the built file. Of course, you would have 2 separate programs executing rather than dynamically changing the one running program. Still, this would be easier than newUIOBJ but it all depends what you are trying to achieve. Mike