Open

The Open event has different arguments for different objects:

Object

See

Application

Syntax 1 For the application object

Window

Syntax 2 For windows


Syntax 1 For the application object

Description

Occurs when the user starts the application.

Event ID

Event ID

Objects

None

Application

Arguments

Argument

Description

commandline

String by value. Additional arguments are included on the command line after the name of the executable program.

Returns

None (do not use a RETURN statement)

Usage

This event can establish database connection parameters and open the main window of the application.

NoteOn Windows You can specify command line arguments when you use the Run command from the Start menu or as part of the Target specification when you define a shortcut for your application.

There is no way to specify command line values when you are testing your application in the development environment.

In other events and functions, you can call the CommandParm function to get the command line arguments.

For an example of parsing the string in commandline, see CommandParm.

Examples

Example 1

This example populates the SQLCA global variable from the application’s initialization file, connects to the database, and opens the main window:

/* Populate SQLCA from current myapp.ini settings */

SQLCA.DBMS = ProfileString("myapp.ini", "database", &

   "dbms", "")

SQLCA.Database = ProfileString("myapp.ini", &

   "database", "database", "")

SQLCA.Userid = ProfileString("myapp.ini", "database", &

   "userid", "")

SQLCA.DBPass = ProfileString("myapp.ini", "database", &

   "dbpass", "")

SQLCA.Logid = ProfileString("myapp.ini", "database", &

   "logid", "")

SQLCA.Logpass = ProfileString("myapp.ini", &

   "database", "LogPassWord", "")

SQLCA.Servername = ProfileString("myapp.ini", &

   "database", "servername", "")

SQLCA.DBParm = ProfileString("myapp.ini", "database", &

   "dbparm", "")


CONNECT;


IF SQLCA.Sqlcode <> 0 THEN

   MessageBox("Cannot Connect to Database", &

      SQLCA.SQLErrText)

   RETURN

END IF


/* Open MDI frame window */

Open(w_genapp_frame)

See also


Syntax 2 For windows

Description

Occurs when a window is opened by one of the Open functions. The event occurs after the window has been opened but before it is displayed.

Event ID

Event ID

Objects

pbm_open

Window

Arguments

None

Returns

Long. Return code choices (specify in a RETURN statement):

Usage

These functions trigger the Open event:

When the Open event occurs, the controls on the window already exist (their Constructor events have occurred). In the Open event script, you can refer to objects in the window and affect their appearance or content. For example, you can disable a button or retrieve data for a DataWindow.

Some actions are not appropriate in the Open event, even though all the controls exist. For example, calling the SetRedraw function for a control fails because the window is not yet visible.

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:

// w_1 Open event script 
close(this)
open(w_2) // causes crash

This code does not cause a crash:

// w_1 ue_postopen event script 
close(this)

// w_1 Open event script 
open(w_2)
this.Post Event ue_postopen()

NoteChanging the WindowState property Do not change the WindowState property in the Open event of a window opened as a sheet. Doing so might result in duplicate controls on the title bar. You can change the property in other scripts once the window is open.

When a window is opened, other events occur, such as Constructor for each control in the window, Activate and Show for the window, and GetFocus for the first control in the window’s tab order.

When a sheet is opened in an MDI frame, other events occur, such as Show and Activate for the sheet and Activate for the frame.

Examples

Example 2

When the window contains a DataWindow control, you can retrieve data for it in the Open event. In this example, values for the transaction object SQLCA have already been set up:

dw_1.SetTransObject(SQLCA)

dw_1.Retrieve( )

See also