CloseUserObject

Description

Closes a user object by removing it from view and executing the scripts for its Destructor event.

Applies to

Window objects

Syntax

windowname.CloseUserObject ( userobjectname ) 

Argument

Description

windowname

The name of the window that contains the user object

userobjectname

The name of the user object you want to close

Returns

Integer. Returns 1 if it succeeds and -1 if an error occurs. If any argument’s value is null, CloseUserObject returns null. The return value is usually not used.

Usage

Use CloseUserObject to close a user object and release the storage occupied by the object and its controls.

When you call CloseUserObject, PowerBuilder removes the object from view, closes it, executes the script for the Destructor event (if any), and then executes the rest of the statements in the script that called the CloseUserObject function.

CloseUserObject also removes the user object from the window’s Control array, which is a property that lists the window’s controls. If the closed user object was not the last element in the array, the index for all subsequent user objects is reduced by one.

After a user object is closed, its properties, instance variables, and controls can no longer be referenced in scripts. If a statement in the script references the closed user object or its properties or instance variables, an execution error will result.

Examples

Example 1

These statements close the user object u_employee and then open the user object u_departments in the window w_personnel:

w_personnel.CloseUserObject(u_employee)

w_personnel.OpenUserObject(u_departments)

Example 2

When the user chooses a menu item that closes a user object, the following excerpt from the menu item’s script prompts the user for confirmation before closing the u_employee user object in the window to which the menu is attached:

IF MessageBox("Close ", "Close?", &

    Question!, YesNo!) = 1 THEN

    // User chose Yes, close user object.

    ParentWindow.CloseUserObject(u_employee)

    // If user chose No, take no action.

END IF

See also