1. RE: newUIObj and IDE
- Posted by "Greg Haberek" <ghaberek at gmail.com> Dec 13, 2007
- 498 views
- Last edited Dec 14, 2007
The easiest way is to use createForm(), which wraps up newUIObj() into a single call. You can also store everything in a text file and read that in with loadForms(). See the "Forms" section of the Win32Lib documentation for more details. In the mean time, here's your code converted to use createForm(), note where I use "name=" and the subsequent calls to getNameId(). Also, I suggest using the w32True and w32False constants when calling things like setVisible() and setEnable(). It makes the code a little more readble and easier to work with down the road.
procedure btnTest_onClick(integer self, integer event, sequence params) sequence form createForm({ "Window, name=Window3, caption=LoginTwo, at=(Center,Center), size=(480,320), flag=WS_DLGFRAME", "LText, name=lblWindow3Top, text=Welcome to Window3, at=(12,4), size=(552,32)", "Group, name=grp_Login2, text=Login, at=(132, 52), size=(304,140)", "EditText, name=txt_UserName2, text=(), at=(100,16), size=(168,28)", "LText, name=lbl_UserName2, text=User Name:, at=(36,20), size=(64,20)", "EditText, name=txtPassword2, text=(), at=(100,52), size=(168,28)", "LText, name=lbl_Password2, text=Password:, at=(40,56), size=(60,20)", "PushButton, name=btn_UserPassword2, text=Submit, at=(180,96), size=(88,28)" }) form = getFormIds( 1 ) if length(form) = 0 then warnErr( "createForm() failed!" ) else setHandler( getNameId("btn_UserPassword2"), w32HClick, routine_id("btn_UserPassword2_onClick")) setVisible( Window1, w32False ) openDialog( getNameId("Window3") ) setVisible( Window1, w32True ) -- we call destroy() here to prevent the same -- form from being created over and over again destroy( getNameId("Window3") ) end if end procedure setHandler( btnTest, w32HClick, routine_id("btnTest_onClick"))
-----Original Message----- From: Mike777 [mailto:guest at RapidEuphoria.com] Sent: Thursday, December 13, 2007 2:45 PM To: EUforum at topica.com Subject: newUIObj and IDE posted by: Mike777 <anon4321 at gmail.c?m> Another newbie question, I'm afraid. Having solved all of the previously noted issues (thanks) I now move on to using the newUIObj() routine to attempt to create new controls dynamically. I have an example from the IDE which builds Window1 and Window2. I also put in an empty Window3 and manually put the following code behind the click event of a Test button on Window1. The intent is to have Window3 look and act just like Window2 (and it does):
procedure btnTest_onClick (integer self, integer event, sequence params) integer lblWindow3Top,grp_Login2,txt_UserName2,lbl_UserName2 integer txtPassword2,lbl_Password2,btn_UserPassword2 lblWindow3Top = createEx( LText, "Welcome to Window3", Window3, 12, 4, 552, 32, 0, 0 ) grp_Login2 = createEx( Group, "Login", Window3, 132, 52, 304, 140, 0, 0 ) txt_UserName2 = createEx( EditText, "", grp_Login2, 100, 16, 168, 28, 0, 0 ) lbl_UserName2 = createEx( LText, "User Name:", grp_Login2, 36, 20, 64, 20, 0, 0 ) txtPassword2 = createEx( EditText, "", grp_Login2, 100, 52, 168, 28, w32or_all({ES_PASSWORD}), 0 ) lbl_Password2 = createEx( LText, "Password:", grp_Login2, 40, 56, 60, 20, 0, 0 ) btn_UserPassword2 = createEx( PushButton, "Submit", grp_Login2, 180, 96, 88, 28, 0, 0 ) setHandler( btn_UserPassword2, w32HClick, routine_id("btn_UserPassword2_onClick")) setVisible(Window1,0) openDialog(Window3) setVisible(Window1,1) end procedure setHandler( btnTest, w32HClick, routine_id("btnTest_onClick"))
I've put the btn_UserPassword2_onClick routine somewhere else (in the general routine for Window1) and it is called successfully from Window3 when it fires. When I click on the btnTest button in Window1, Window3 opens up with the expected controls (looks just like the Login screen I previously posted which is built by the IDE as Window2). I would like to replace the above with calls to newUIObj(). I don't want to embarrass myself by posting all the attempts I've made. Suffice it to say that they don't work. If somebody can show me the code to insert a single control onto a previously existing Window3 when clicking the btnTest button on Window1 that would be enough to get me going. Thanks Mike
2. RE: newUIObj and IDE
- Posted by c.k.lester <euphoric at ck?este?.com> Dec 13, 2007
- 515 views
- Last edited Dec 14, 2007
Here's an example to get you started:
include win32lib.ew atom Window1 sequence form createForm({ "Window, name=Window3, caption=LoginTwo, at=(Center,Center),size=(480,320), flag=WS_DLGFRAME", "LText, name=lblWindow3Top, text=Welcome to Window3, at=(12,4),size=(552,32)", "Group, name=grp_Login2, text=Login, at=(132, 52), size=(304,140)", "EditText, name=txt_UserName2, text=(), at=(100,16), size=(168,28)", "LText, name=lbl_UserName2, text=User Name:, at=(36,20),size=(64,20)", "EditText, name=txtPassword2, text=(), at=(100,52), size=(168,28)", "LText, name=lbl_Password2, text=Password:, at=(40,56),size=(60,20)", "PushButton, name=btn_UserPassword2, text=Submit, at=(180,96),size=(88,28)" }) form = getFormIds( 1 ) Window1 = getNameId("Window3") if length(form) = 0 then warnErr( "createForm() failed!" ) else setHandler( getNameId("btn_UserPassword2"), w32HClick,routine_id("btn_UserPassword2_onClick")) setVisible( Window1, w32False ) openDialog( Window1 ) setVisible( Window1, w32True ) -- we call destroy() here to prevent the same -- form from being created over and over again --destroy( getNameId("Window3") ) end if startApp(w32NoCallBack)
3. RE: newUIObj and IDE
- Posted by c.k.lester <euphoric at cklester?co?> Dec 13, 2007
- 501 views
- Last edited Dec 14, 2007
c.k.lester wrote: > > Here's an example to get you started: Oops. That last post was incomplete.
include win32lib.ew createForm({ "Window, name=Window3, caption=LoginTwo, at=(Center,Center),size=(480,320), flag=WS_DLGFRAME", "LText, name=lblWindow3Top, text=Welcome to Window3, at=(12,4),size=(552,32)", "Group, name=grp_Login2, text=Login, at=(132, 52), size=(304,140)", "EditText, name=txt_UserName2, text=(), at=(100,16), size=(168,28)", "LText, name=lbl_UserName2, text=User Name:, at=(36,20),size=(64,20)", "EditText, name=txtPassword2, text=(), at=(100,52), size=(168,28)", "LText, name=lbl_Password2, text=Password:, at=(40,56),size=(60,20)", "PushButton, name=btn_UserPassword2, text=Submit, at=(180,96),size=(88,28)" }) startApp(w32NoCallBack)
This is just a simple example to create and display a window. (Props to Greg! :))
4. RE: newUIObj and IDE
- Posted by Mike777 <anon4321 at gmail??om> Dec 13, 2007
- 491 views
- Last edited Dec 14, 2007
Thanks to both of you. I think I may have what I need based on what you posted, but I am wondering why both of you say that the easiest thing to do is to use create form? What I intend to do will be a bit more granular than that and I'm not looking forward to generating code which will necessarily work at the form level. If I have 75 controls on a window and want to add one more, I really can't see myself destroying the form and recreating it from scratch. Is there a simple example of using the newUIObj function directly which would add a single control to an already existing window/form? Thanks Mike
5. RE: newUIObj and IDE
- Posted by c.k.lester <euphoric at cklest?r.?om> Dec 13, 2007
- 510 views
- Last edited Dec 14, 2007
Mike777 wrote: > > Thanks to both of you. I think I may have what I need based on what you > posted, > but I am wondering why both of you say that the easiest thing to do is to use > create form? I didn't mean to imply that create form was easiest. I just modified Greg's code because it didn't work for me when I ran it. I think newUIObj() can then be used to add controls. > If I have 75 controls on a window and want to add one more, I really > can't see myself destroying the form and recreating it from scratch. Yeah, that wouldn't be what I like to call "smart." > Is there a simple example of using the newUIObj function directly which would > add a single control to an already existing window/form? I'm sure Derek will post a wonderful example soon! :)
6. RE: newUIObj and IDE
- Posted by Matt Lewis <matthewwalkerlewis at ?mail.com> Dec 14, 2007
- 489 views
Mike777 wrote: > > Thanks to both of you. I think I may have what I need based on what you > posted, > but I am wondering why both of you say that the easiest thing to do is to use > create form? What I intend to do will be a bit more granular than that and > I'm not looking forward to generating code which will necessarily work at the > form level. If I have 75 controls on a window and want to add one more, I > really > can't see myself destroying the form and recreating it from scratch. > > Is there a simple example of using the newUIObj function directly which would > add a single control to an already existing window/form? I must say, I've never really understood the draw of the newUIObj way of doing things. As CK mentioned before, what I would do is probably to keep everything in a sequence. You could have another sequence that stored creation parameters, if you want, and use that to dynamically create the controls (although this requirement has me somewhat puzzled). Matt
7. RE: newUIObj and IDE
- Posted by Mike777 <anon4321 at gmai?.?om> Dec 14, 2007
- 503 views
Matt Lewis wrote: > I must say, I've never really understood the draw of the newUIObj way of > doing things. My reason for doing it is that it appears to be the only way I can name the control myself through a variable value determined by the program at run time. I need that so I can drive everything from my database. > As CK mentioned before, what I would do is probably to keep > everything in a sequence. You could have another sequence that stored > creation parameters, if you want, and use that to dynamically create the > controls (although this requirement has me somewhat puzzled). No, I can't, because I haven't figured out the syntax, yet. But I'm working on it! Hopefully, somebody will take pity on me and realize that, while I've received a whole bunch of replies, not a single one includes the syntax and the framework necessary. I can't seem to find an example anywhere in the docs or the demos, or, for that matter, on the web for adding, say, a list, to a pre-existing window/form/frame. Plenty of references to newUIObj (well, at least a handful), but no examples which work on my machine. But, yes, I can easily populate a sequence with creation parameters by reading the database which will be pre-loaded with certain information and then modified on the fly by the program as it runs. Mike
8. RE: newUIObj and IDE
- Posted by Derek Parnell <ddparnell at bigpond?co?> Dec 14, 2007
- 513 views
Mike777 wrote: > > Matt Lewis wrote: > > > I must say, I've never really understood the draw of the newUIObj way of > > doing things. > > My reason for doing it is that it appears to be the only way I can name the > control myself through a variable value determined by the program at run time. > I need that so I can drive everything from my database. Have you looked at 'setIdName'? This allows you to give a name to any control and then you can later use 'getNameId' to fetch an ID by supplying its name. If this doesn't help, I'll knock up a simple example of how to use newUIObj to insert controls into an existing Window (form). -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
9. RE: newUIObj and IDE
- Posted by CChris <christian.cuvier at agriculture?gouv.f?> Dec 14, 2007
- 491 views
Mike777 wrote: > > Matt Lewis wrote: > > > I must say, I've never really understood the draw of the newUIObj way of > > doing things. > > My reason for doing it is that it appears to be the only way I can name the > control myself through a variable value determined by the program at run time. > I need that so I can drive everything from my database. > > > As CK mentioned before, what I would do is probably to keep > > everything in a sequence. You could have another sequence that stored > > creation parameters, if you want, and use that to dynamically create the > > controls (although this requirement has me somewhat puzzled). > > No, I can't, because I haven't figured out the syntax, yet. But I'm working on > it! Hopefully, > somebody will take pity on me and realize that, while I've received a whole > bunch of replies, > not a single one includes the syntax and the framework necessary. > > I can't seem to find an example anywhere in the docs or the demos, or, for > that > matter, on the web for adding, say, a list, to a pre-existing > window/form/frame. > Plenty of references to newUIObj (well, at least a handful), but no examples > which work on my machine. > > But, yes, I can easily populate a sequence with creation parameters by reading > the database which will be pre-loaded with certain information and then > modified > on the fly by the program as it runs. > > Mike To add a control to a window, just create it on the spot as child of that window, at the right position. You can always update the form text by appending data for this control to it for future use. No need to reload. The name of any control is anything you supply to setIdName(id,Name), made standard. Docs say: | -- This routine ensures that only alphanumeric and '_' characters are in the name. All | -- other characters stripped off the /Name parameter. I'm not sure why ASCII 128-255 are filtered out, or why UTF-16 encoded chars wouldn't fly. Not a top priority, but I'll remember looking into it. When a control has a name, you can get its id using getNameId() and getNameIdInContext(). To get the id of a form window, use getFormIds(). What you cannot do is defining a variable with a dynamic name. Using macros in your programming editor would be more efficient - but unfortunately not portable, which is why Eu might benefit from a dedicated macro system, or standard preprocessor if you like -. As Matt suggested, you can always emulate this facility using an associative array, ie a pair of sequences, one holding "variable names" and one holding corresponding "variable values". This means no type checking - unless you implement it (based on the name for instance) -, and slower access, of course. CChris