James Russell Posted February 8, 2011 Share Posted February 8, 2011 Hey all, I've been reading through several past topics on creating dialog boxes but have been able to find anything covering custom dialogs. I want to create a dialog that has 4 fields (see attached sketch), one of which is a Text input, CLETTER, the other three are numbers, CNUM, STNUM, ENDNUM. Reading through the VS guide relating to CreateLayout and a whole heaps of functions relating to that but I don't quite see how the structure works, nor how I can retain the values for later use. Would anyone be able to do a quick example or point me to a guide? Cheers, J Quote Link to comment
JBenghiat Posted February 8, 2011 Share Posted February 8, 2011 James, For examples, see I'm inserting my dialog skeleton below -Josh {Dialog template} {Replace DNAME} Procedure HeaderPrefs; VAR DNAMEID :LONGINT; {---------------------------------------------------------} PROCEDURE DriveDialog_DNAME(VAR item, data:LONGINT); VAR BEGIN CASE item OF SetupDialogC: BEGIN END; SetDownDialogC: BEGIN END; 1: BEGIN END; END; END; {---------------------------------------------------------} BEGIN {//////// Define dialog ////////} DNAMEID:=CreateLayout('TITLE', HELP_BOOLEAN, 'OK', 'Cancel'); SetFirstLayoutItem(DNAMEID, #####); {//////// Run Dialog ////////} IF VerifyLayout(DNAMEID) THEN BEGIN IF RunLayoutDialog(DNAMEID, DriveDialog_DNAME) = 1 THEN BEGIN END; END; END; Run(HeaderPrefs); 1 Quote Link to comment
James Russell Posted February 8, 2011 Author Share Posted February 8, 2011 As an update I've made: PROCEDURE RDT; VAR dialog1 :INTEGER; result :INTEGER; PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT); BEGIN END; BEGIN dialog1 := CreateLayout('Control Tables', FALSE, 'OK', 'Cancel'); CreateStaticText(dialog1, 3, 'Control Equipment:', 25); SetFirstLayoutItem(dialog1, 3); CreateEditText(dialog1, 4, 'R/D', 6); SetBelowItem(dialog1,3,4,0,0); CreateEditReal(dialog1, 5, 1, 0, 6); SetRightItem(dialog1,4,5,3,0); CreateStaticText(dialog1, 6, 'Starting Number:', 25); SetBelowItem(dialog1,4,6,0,0); CreateEditReal(dialog1, 7, 1, 1, 6); SetBelowItem(dialog1,6,7,0,0); CreateStaticText(dialog1, 8, 'Ending Number:', 25); SetBelowItem(dialog1,7,8,0,0); CreateEditReal(dialog1, 9, 1, 12, 6); SetBelowItem(dialog1,8,9,0,0); result := RunLayoutDialog(dialog1, Dialog_Handler); END; RUN(RDT); It looks all pretty and happy but how do I store the values into my variables that I want? Maybe this is more a question of getting values out of boxes Any insight much appreciated. J Quote Link to comment
James Russell Posted February 8, 2011 Author Share Posted February 8, 2011 Josh, I have no idea how close we must have been to posting next to each other because I didn't even see you when I replied. I think I'm doing ok on the creation front, I just need to extract my data now, how do I get my data back from this LONGINT goodness and put it into REAL vals and STRINGS and such? Thanks, J Quote Link to comment
JBenghiat Posted February 9, 2011 Share Posted February 9, 2011 James, You need to work on your handler. See my template for the basic structure. Ultimately, in the case of event 1 (OK button) you want to set a global variable (ie. a variable in the top most list) for each of your fields. If you want to make your dialogs more sophisticated, the event for each field should check if the user has entered a valid result, then toggle the status of the OK button. See if the examples to which I linked are a help (I haven't looked at them in a while but remember they were useful). Also note, 2010 introduced a bunch of new methods for getting and setting field values. Both the old and new methods currently work, but the old ones will be phased out in a version or two. Hope this brief reply helps. -Josh Quote Link to comment
James Russell Posted February 9, 2011 Author Share Posted February 9, 2011 Josh, Thanks for the links and showing your template. I've looked through the examples on custom dialogs, in particular the 'create light' example which deals with the custom dialog quite a lot. There seems to be a lot of GetControlData going on which after a lot of reading I don't quite get the context nor usage of in relation to the CreateLayout, saving data to a LONGINT, nor much else. Also don't yet understand the purpose of the DriveDialog in your example or Dialog_Handler in mine. What is the purpose of it within the structure of the code? Much appreciated, J Quote Link to comment
JBenghiat Posted February 9, 2011 Share Posted February 9, 2011 James, There are two components to dialogs, the layout and the driver. It looks like you have a handle on the layout, which draws the dialog. The driver runs the dialog. Basically, every time a user interacts with the dialog, the driver procedure runs. Vectorworks passes the ID of the item that was interacted with to the driver (you can ignore event for now). In the driver, you can place a case statement to do different things depending on which item was used. Item 1 is always OK and 2 Cancel. SetUpDialogC is the item constant that is passed immediately after the dialog draws (you would set fields to default or current data in this section). In the OK section, use GetItemText or GetEditInteger to get your values. See http://developer.vectorworks.net/index.php?title=Category:VS_Function_Reference:Dialogs_-_Modern for details. HTH, Josh Quote Link to comment
James Russell Posted February 13, 2011 Author Share Posted February 13, 2011 Josh, Many thanks for your reply, after much trial and error and help from some great mates I've cracked open the beast that is the custom dialog. For anyone who's looking for it here is my test code. PROCEDURE RDT; VAR dialog1, result :INTEGER; STNUM, ENDNUM, RDVAL :REAL; RDSTR :STRING; success :BOOLEAN; WSH :HANDLE; {--------------------------Dialog Handler-------------------------------} PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT); BEGIN Message('The item is',item); CASE item OF 1: BEGIN GetItemText(dialog1,4,RDSTR); success := GetEditReal(dialog1,5,2,RDVAL); success := GetEditReal(dialog1,7,2,STNUM); success := GetEditReal(dialog1,9,2,ENDNUM); END; END; END; {--------------------------Layout Creation------------------------------} BEGIN {//Create Dialog//} dialog1 := CreateLayout('Control Tables', FALSE, 'OK', 'Cancel'); {//Dialog Layout//} CreateStaticText(dialog1, 3, 'Control Equipment:', 25); SetFirstLayoutItem(dialog1, 3); CreateEditText(dialog1, 4, 'R/D', 6); SetBelowItem(dialog1,3,4,0,0); CreateEditReal(dialog1, 5, 1, 0, 6); SetRightItem(dialog1,4,5,3,0); CreateStaticText(dialog1, 6, 'Starting Number:', 25); SetBelowItem(dialog1,4,6,0,0); CreateEditReal(dialog1, 7, 1, 1, 6); SetBelowItem(dialog1,6,7,0,0); CreateStaticText(dialog1, 8, 'Ending Number:', 25); SetBelowItem(dialog1,7,8,0,0); CreateEditReal(dialog1, 9, 1, 12, 6); SetBelowItem(dialog1,8,9,0,0); IF VerifyLayout(dialog1) THEN BEGIN If RunLayoutDialog(dialog1, Dialog_Handler) = 1 THEN BEGIN WSH:=CreateWS(Concat(RDSTR,RDVAL,'- Control Table ',Date(2,1)),25,10); SetWSCellFormula(WSH,1,1,1,1,RDSTR); SetWSCellFormula(WSH,1,2,1,2,concat('=',num2Str(2,RDVAL))); SetWSCellFormula(WSH,1,3,1,3,concat('=',num2Str(2,STNUM))); SetWSCellFormula(WSH,1,4,1,4,concat('=',num2Str(2,ENDNUM))); END; END; END; RUN(RDT); Cheers, J Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.