WindowClose

(Engine-Level Function)

Description: Returns true if an attempt is made to close the window.
Returns: Boolean
Usage: Steady State only.
Function Groups: Window
Related to: VStatus | Window | WindowOptions
Format: WindowClose(Object)
Parameters:  
Object   
Required. Any expression that returns the object value of any module instance drawn in the window.
Comments:

Only one WindowClose() should run with a window at a given time.
WindowClose() can be used inside a window that you opened with a Window() call.
For any page or widget, or other window do not use WindowClose because you cannot know if WindowClose is already being used with that window (as is likely the case).

If this function is active when an attempt to close a window is made, the window will not close, and the module(s) in that window will not stop. It is up to the calling module to close the window and stop the module(s) by switching to another state.
This function may be used to control what happens when a window is closed (or to prevent it from being closed). When the attempt is made to close the window, an action (or actions) can be triggered. For example, this might write some data to file. Then a variable could be set (or a value could be returned by the module) which signals the calling module to switch states, which closes the window and stops the module(s) inside.

Notes on closing a window:

When WindowClose behavior is active, the typical way to close a window is by making one of the following happen:

  • The Enable parameter to the Window() function changes to false.
  • The state where the Window() function is running in steady state stops. This is typically achieved by doing one of two things:
    • The calling object's state changes away from the state containing the Window() function.
    • The calling object is slain.

 

Calling Slay on the root object of the window does not work. (For example, calling Slay(Self) from the window's root object.) The root object of the window is called in steady-state, from the Window function's 7th parameter. Slaying an object that has been called in steady-state does nothing because it does not affect the calling object: the calling object would still be in it's same state with that same Window() call running, and therefore the called Window module cannot be permitted to stop.

If the calling object is launched, then a common approach is to slay that calling object. For example, Slay(Caller(Self)) rather than Slay(Self) may work, depending on how the object was launched.

It is possible for a WindowClose statement to be associated with a window, but to not yet be running when the attempt to close the window is made. If this happens the slay of the module running in the window will continue up the module tree until a running WindowClose is found, or the top of the tree is reached. This behavior may be undesirable. The scenario can be avoided by setting bit 19 of the Style option in the Window statement. Doing so will warn VTScada that a WindowClose statement will be associated with this window.

Example:

  If WindowClose(Self()) CloseEverything;

This statement causes a state change to CloseEverything if the user attempts to close the current window. It is then up to code in CloseEverything to perform any necessary clean-up tasks and close the window.