### bonjour2.sml ### Sample script for Building Dialogs in SML ### Illustrates the use of dialog control callbacks ### in a script tag in the dialog specification. ### Global variable declarations numeric errXML, dlgreturn; string xmlfile$; # clear the console window clear(); ### create string with path and filename of XML file with the ### dialog specification (assumed to be in same directory as this script) xmlfile$ = _context.ScriptDir + "/bonjour2.xml"; ### read and parse XML file; returns an error code (number < 0 ) if there are syntax errors class XMLDOC doc; errXML = doc.Read(xmlfile$); if (errXML < 0) { PopupError(errXML); # Popup an error dialog. "Details" button shows syntax errors. Exit(); } ### declare class instance for the dialog element in the XML structure ### and get the dialog handle from the XML structure. ### Pop up an error dialog and exit if the dialog ID can't be found in the XML. class XMLNODE dlgnode; dlgnode = doc.GetElementByID("hello"); if (dlgnode == 0) { PopupMessage("Could not find dialog node in XML document"); Exit(); } ### declare class instance for the dialog window and set the XML structure ### in memory as the source for the dialog. class GUI_DLG dlg; dlg.SetXMLNode(dlgnode); ### open as a modal dialog; the DoModal() method doesn't return until the dialog is ### closed; it returns -1 if the user presses [Cancel], or 0 if the user presses [OK]. dlgreturn = dlg.DoModal(); if (dlgreturn == -1) { # exit script when Cancel button on dialog is pressed Exit(); }