// A very simple example to show how to create a single button dialog
// The use of constructors and destructors is illustrated. In this example
// the destructor, which gets called when the dialog is closed, simply prints 
// a message in the results window. This confirms that the destructor has
// been called when the dialog is closed. If the destructor is not 
// invoked, then variables used by the dialog may not go out of scope when
// the dialog object is closed. This leads to variables such as images, left
// hanging in memory and a memory leak ensues. Extensive date processing with such dialogs
// can lead to problems such as crashes and hangs as memory gets used up.

// D. R. G. Mitchell, adminnospam@dmscripting.com
// version:20100831, v1.0, Aug 2010.


// the class createbuttondialog is of the type user interface frame, and responds to interaction
// the dialog

class CreateButtonDialog : uiframe
{

	//this is the response when the button is pressed

	void buttonresponse(object self)
		{

			
			Beep()
			okdialog("You pressed my button!")
			return

		}


// this function creates a taggroup containing the dialog elements:
// a box within which a simple button is present.

taggroup MakeDialog(object self)
	{

		TagGroup dialog_items;	
		TagGroup dialog = DLGCreateDialog("Example Dialog", dialog_items)

		// Creates a box in the dialog which surrounds the button

		taggroup box_items
		taggroup box=dlgcreatebox("  Parameters  ", box_items)
		box.dlgexternalpadding(5,5)
		box.dlginternalpadding(25,25)

	// Creates the button

		TagGroup ExampleButton = DLGCreatePushButton("Push Me", "buttonresponse")
		examplebutton.dlgexternalpadding(10,10)

		box_items.dlgaddelement(examplebutton)
		dialog_items.dlgaddelement(box)
		return dialog

	}

// The constructor this calls the makedialog() function and displays it

createbuttondialog(object self)
	{

		// Construct the dialog

		self.init( self.makeDialog() );
		self.display("Dialog Template")
		result("\nConstructor called.")
	}

// The destructor is called when the object (the dialog) is closed

~createbuttondialog(object self)
	{
		result("\nDestructor called - bye!")
	}
}

// allocates the above function which puts it all together

alloc(createbuttondialog)