Lifetime of XAD objects
An XAD object will exist until the model ends or until it is destroyed using XADdestroy. The object-specific routines (listed in the reference part of this document) can only operate on an object when the window containing the object is active (or, if the object is a window, only while the window is active). For this reason, the event XAD_EVENT_WINDOW_OPENED is of particular interest: it is the only chance to operate on the objects in a window before the window begins interacting with the user.
There are two distinct ways in which windows may behave:
- When a window is opened (using XADwindowopen), the window takes control of the Mosel program. Until the window is closed (using XADwindowclose) the only way to execute code is from the event handler (directly, or by calling a subroutine). The statement following XADwindowopen will only be executed after the user has closed the window. This behavior can be used when user input is necessary before the program can continue or when the user interface is meant to control the Mosel program. This type of window is referred to as a modal dialog.
- When a window is shown (using XADwindowshow), the window is displayed and Mosel continues immediately. A shown window should be used as an auxiliary window for monitoring program state, to display progress, etc. When the monitoring is complete (e.g. at the end of the Mosel run), the window may be hidden, using XADwindowhide. If the window is not hidden before the Mosel run ends, it will persist until the model is unloaded from memory (in Xpress-IVE this only happens when compiling or running a model). This type of window is referred to as a modeless dialog.
It is important to make a correct choice between the two behaviors. Experiment until the distinction is well understood, and keep in mind that for most purposes a window should be opened in order to allow it to take control of the program execution by generating events.
If you have any comments or suggestions about these pages, please send mail to docs@dashoptimization.com.