Syntax 1 For windows
Description
Closes a window and releases the storage occupied by the window
and all the controls in the window.
Controls
Window objects
Syntax
|
1 |
<span>Close</span> ( <span>windowname</span> ) |
|
Argument |
Description |
|---|---|
|
windowname |
The name of the window you want to close |
Return Values
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 |
// w_1 Open event script <br>close(this)<br>open(w_2) // causes crash |
This code does not cause a crash:
|
1 |
// w_1 ue_postopen event script <br>close(this) |
|
1 |
// w_1 Open event script <br>open(w_2)<br>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 |
<span>Close</span>(w_employee) |
|
1 |
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 |
IF MessageBox('ExitApplication', & |
|
1 |
'Exit?', Question!, YesNo!) = 2 THEN |
|
1 |
// If no, stop window from closing |
|
1 |
RETURN 1 |
|
1 |
END IF |