Open event
The Open event has different arguments for different
objects:
Object |
See |
---|---|
Application |
|
Window |
Syntax 1 For the application object
Description
Occurs when the user starts the application.
Event ID
Event ID |
Objects |
---|---|
None |
Application |
Parameters
Argument |
Description |
---|---|
commandline |
String by value. |
Return Values
None (do not use a RETURN statement)
Usage
This event can establish database connection parameters and
open the main window of the application.

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
This example populates the SQLCA global variable
from the application’s initialization file, connects to
the database, and opens the main window:
1 |
/* Populate SQLCA from current myapp.ini settings */ |
1 |
SQLCA.DBMS = ProfileString("myapp.ini", "database", & |
1 |
   "dbms", "") |
1 |
SQLCA.Database = ProfileString("myapp.ini", & |
1 |
   "database", "database", "") |
1 |
SQLCA.Userid = ProfileString("myapp.ini", "database", & |
1 |
   "userid", "") |
1 |
SQLCA.DBPass = ProfileString("myapp.ini", "database", & |
1 |
   "dbpass", "") |
1 |
SQLCA.Logid = ProfileString("myapp.ini", "database", & |
1 |
   "logid", "") |
1 |
SQLCA.Logpass = ProfileString("myapp.ini", & |
1 |
   "database", "LogPassWord", "") |
1 |
SQLCA.Servername = ProfileString("myapp.ini", & |
1 |
   "database", "servername", "") |
1 |
SQLCA.DBParm = ProfileString("myapp.ini", "database", & |
1 |
   "dbparm", "") |
1 |
1 |
CONNECT; |
1 |
1 |
IF SQLCA.Sqlcode <> 0 THEN |
1 |
   MessageBox("Cannot Connect to Database", & |
1 |
      SQLCA.SQLErrText) |
1 |
   RETURN |
1 |
END IF |
1 |
1 |
/* Open MDI frame window */ |
1 |
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 |
Parameters
None
Return Values
Long. Return code choices (specify in
a RETURN statement):
-
0 Continue
processing
Usage
These functions trigger the Open event:
-
Open
-
OpenWithParm
-
OpenSheet
-
OpenSheetWithParm
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:
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() |

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
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:
1 |
dw_1.SetTransObject(SQLCA) |
1 |
dw_1.Retrieve( ) |