home products news downloads documentation support gallery online maps resellers search
TNTmips Downloads Menu

HOME

CONTACT US

CURRENT RELEASE
  TNT 2013

DEVELOPMENT VERSION
  TNT 2014

TNTmips Pro
PRIOR RELEASES
  TNT 2012

FREE SOFTWARE
  TNTmips Free
  TNTatlas
  TNTsdk

MORE DOWNLOADS
  HASP Key Driver
  Screen Recorder
  TNT Language Kits
  Sample Geodata
  TNT Scripts

DOCUMENTATION
  TNTmips Tutorials
  Tutorial Datasets
  Technical Guides
  Scripts
  Quick Guides

MORE INFO
  Download FAQs
  FTP
  Download Managers
  Find Reseller

SITE MAP


xmldlg.sml

       See other examples and scripts with XML...


## xmldlg.sml

## Sample script that creates a test dialog named
## "This is a test" from an dialog specification in an
## external XML file "test.xml".  The dialog has several
## tabbed panels with examples of various available controls.

## The script also demonstrates methods to set control values
## from the script and to read the dialog settings set by the
## user.  Values for the dialog controls are printed to the
## Console Window as an example. 
 
## Most class variables are declared as needed in the script to 
## clarify their relevance to the remaining code.

## Variable declarations
numeric err, ret;
string xmlfile$;
class GUI_DLG  dlg;

### Define test callback function #########
func TestFunc() {
	PopupMessage("I Said Ignore it!");
	}

### Define callback procedure to retrieve dialog settings ######
proc GetDlgValues() {
	# Here are four ways to get settings out of the dialog.  The extracted values are printed
	# to the console window as an example.

	#  1 -- Use the GetValues() class method in GUI_DLG to get all of the control settings at
	#			at once.  They are returned to a previously-declared instance of class GUIFORMDATA.
	#			Use GetValue...() methods in that class to read the values as needed.
	printf("Method 1...\n");
	class GUI_FORMDATA data;
	data = dlg.GetValues();
	printf("  RadioGroup value = %s\n", data.GetValueStr("radiogroup") );
	printf("  FirstName: %s\n", data.GetValueStr("fname") );
	printf("  Togglebutton numeric value = %d\n", data.GetValueNum("tbutton") );
	printf("  Togglebutton string value = %s\n\n", data.GetValueStr("tbutton") );

	#  2 -- Use GetCtrlValueNum() and GetCtrlValueStr() class methods in GUI_DLG to ask the dialog   
	#			for each control value individually as needed.  No GUI_FORMDATA class instance is required.   
	#			Less efficient than #1 if multiple control values are needed.  Internally it calls  
	#			dlg.GetValues(), pulls out the one value asked for, and discards the rest.
	printf("Method2...\n");
	printf("  RadioGroup value = %s\n", dlg.GetCtrlValueStr("radiogroup") );
	printf("  FirstName: %s\n", dlg.GetCtrlValueStr("fname") );
	printf("  Togglebutton numeric value = %d\n", dlg.GetCtrlValueNum("tbutton") );
	printf("  Togglebutton string value = %s\n\n", dlg.GetCtrlValueStr("tbutton") );

	#  3 -- Use the GetCtrlByID() method in GUI_DLG to get the control handle for a control class,
	#			then a GetValue...() method in the individual GUI_CTRL_... class to read the control 
	#			value individually as needed.
	printf("Method3...\n");
	class GUI_CTRL_EDIT_STRING fname;
	class GUI_FORM_RADIOGROUP radio;
	class GUI_CTRL_TOGGLEBUTTON tbutton;
	fname = dlg.GetCtrlByID("fname");
	radio = dlg.GetCtrlByID("radiogroup");
	tbutton = dlg.GetCtrlByID("tbutton");
	printf("  RadioGroup value = %s\n", radio.GetSelected() );
	printf("  FirstName: %s\n", fname.GetValue() );
	printf("  Togglebutton numeric value = %d\n", tbutton.GetValueNum() );
	printf("  Togglebutton string value = %s\n\n", tbutton.GetValueStr() );

	#  4 -- A more compact (but perhaps less clear) version of method 3.  Methods to get the control
	#			handle and its value are strung together, eliminating the need to declare the control handle
	#			class variable.
	printf("Method 4...\n");
	printf("  RadioGroup value = %s\n", dlg.GetCtrlByID("radiogroup").GetValueStr() );
	printf("  FirstName: %s\n", dlg.GetCtrlByID("fname").GetValueStr() ); 
	printf("  Togglebutton numeric value = %d\n", dlg.GetCtrlByID("tbutton").GetValueNum() );
	printf("  Togglebutton string value = %s\n\n", dlg.GetCtrlByID("tbutton").GetValueStr() );

	# NOTE: if the control value must be accessed in several places, store it as a variable for
	# reuse.  Values read from GUIFORMDATA or the dialog would be stored as numeric or string
	# variables.

	}	# end GetDlgValues()


############# Main script ##################
clear();		# clear the console window

class XMLDOC doc;
xmlfile$ = _context.ScriptDir + "/test.xml";		# read and parse the dialog specification
err = doc.Read(xmlfile$);
if (err < 0) {
	PopupError(err);	# Popup an error dialog.  "Details" button will say what's wrong.
	Exit();
	}

class XMLNODE dlgnode;
dlgnode = doc.GetElementByID("test");		# get the dialog element from the parsed XML
if (dlgnode == 0) {
	PopupMessage("Could not find dialog node in XML document");
	Exit();
	}

dlg.SetXMLNode(dlgnode);		# set the XML dialog element as the source for the dialog class
dlg.SetCtrlValueStr("fname", "Fred");		# set value for edittext control
dlg.SetCtrlValueStr("radiogroup", "button2");	# set value for radiogroup control

ret = dlg.DoModal();			# open as modal dialog
# Note: ret will be -1 if user hit cancel, 0 for OK

printf("DoModal() returned %d\n", ret);



Back Home ©MicroImages, Inc. 2013 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010   USA
Business & Sales: (402)477-9554  Support: (402)477-9562  Fax: (402)477-9559
Business info@microimages.com  Support support@microimages.com  Web webmaster@microimages.com

25 March 2009

page update: 26 May 11