Syntax 1: For windows
Description
Closes a window and releases the storage occupied by the window
and all the controls in the window.
Applies to
Window objects
Syntax
1 |
Close ( windowname ) |
Argument |
Description |
---|---|
windowname |
The name of the window you want to |
Return value
Integer.
Returns 1 if it succeeds and -1 if an error occurs. If
windowname is null, Close returns null. The return value is usually not
used.
Usage
Use Syntax 1 to close a window and release the storage occupied by
the window and all the controls in the window.
When you call Close, PowerBuilder removes the window from view,
closes it, executes the scripts for the CloseQuery and Close events (if
any), and then executes the rest of the statements in the script that
called the Close function. Do not call Close from the CloseQuery or
Close events, since this produces an endless loop.
After a window is closed, its properties, instance variables, and
controls can no longer be referenced in scripts. If a statement in the
script references the closed window or its properties or instance
variables, an execution error will result.
Closing a window by calling the Close function in any of the
window’s events or in an event of any control on the window can cause
PowerBuilder to crash if the Close function is not the last statement in
the event script. You can avoid this issue by calling the Close function
in the last statement of the event script, or in a user-defined event
that is posted from the event script. For example, the following code in
the Open event script for a window called w_1 can cause a crash:
1 2 3 |
// w_1 Open event script close(this) open(w_2) // causes crash |
This code does not cause a crash:
1 2 3 4 5 6 |
// w_1 ue_postopen event script close(this) // w_1 Open event script open(w_2) this.Post Event ue_postopen() |
Preventing a window from closing
You can prevent a window from being closed with a return code of
1 in the script for the CloseQuery event. Use the RETURN
statement.
Examples
These statements close the window w_employee and then open the
window w_departments:
1 2 |
Close(w_employee) Open(w_departments) |
After you call Close, the following statements in the script for
the CloseQuery event prompt the user for confirmation and prevent the
window from closing:
1 2 3 4 5 |
IF MessageBox('ExitApplication', & 'Exit?', Question!, YesNo!) = 2 THEN // If no, stop window from closing RETURN 1 END IF |
See also