Designing the application

The application you design for use with the PowerBuilder window ActiveX can be much the same as other PowerBuilder applications you develop; however, there are some restrictions and considerations to keep in mind. This section discusses:

Window management

Initial child window Your initial window needs to be a child window that lives in the browser frame.

You cannot:

You can:

Closing windows When the client browses to another Web page, the child window on the current Web page is closed, but other windows remain open unless your application closes them. You must close them in the child window’s Close or CloseQuery events.

Do not try to stop the child window from being closed in the CloseQuery event by setting a return value. You cannot prevent the browser from changing to another page and removing the window from view. If the user returns to the page, another instance of your application is started.

Objects

Objects in your PBDs Your PowerBuilder window ActiveX application has access to all objects in the PBDs. This includes functions, structures, and user objects.

System objects Your PowerBuilder window ActiveX application has access to system objects that PowerBuilder instantiates, such as the SQLCA Transaction object and the Message object.

Application object Your PowerBuilder window ActiveX application can access global variables, which are properties of the Application object.

PowerBuilder requires that you have a current Application object during development, but only the application Open event and global variables are used in your application. Any other scripts in the Application object are used only during testing within PowerBuilder.

Scripts and variables

Scripts for application setup If you specify the PBAPPLICATION parameter in the HTML, the PowerBuilder window ActiveX executes the application Open event before opening the child window. You can use this event to establish a database connection and initialize global variables.

NoteThe HTML specifies the window to open Do not open windows from within the application Open event.

If you do not specify the PBAPPLICATION parameter in the HTML, all application setup must be done in the child window, including connecting to the DBMS. The first scriptable events to occur are the constructors for the controls in the window, and then the Open event for the window occurs.

Note that the Activate event does not occur for a child window, so do not do application setup there.

Global variables The PowerBuilder window ActiveX application can access global variables.

Referencing the initial window You cannot reference the initial child window by name in your scripts because PowerBuilder does not create a variable to hold the instance of it. (By contrast, when you instantiate a window yourself by coding the Open function, you always place the instance in a variable that you can then reference.)

As a result, the following code produces an error at runtime (because the window variable w_mychild does not exist):

// This code produces a runtime error:
	w_mychild.title = "The initial window"

But you can code:

// In the child window itself:
	this.title = "The initial window"
	// or
	title = "The initial window"

// In controls of the child window:
	parent.title = "The initial window"

Data access

If your application accesses a DBMS, each client must have a connection to the data source. The connection must be defined on the client’s machine, not the server. The data source can be a local or a network DBMS.

For information about how to connect to a DBMS from the client machine, see Connecting to Your Database.

Remember that the Constructor events for controls occur before the Open event of the window. That means that if you connect to the DBMS in the window’s Open event, the Constructor events cannot get data. You can get data for controls in the window’s Open event, or you can post events from the Constructor events or the window’s Open event.

Paths for external resources

Paths you specify for files must be valid on the client workstation.

If your application uses images as external files, the images must be available at the path specified in the PowerBuilder object. Instead of using external files, you can build image resources into PBDs.

If your application reads or writes local files, the path for those files must be valid on each client’s machine.

In Windows environments, if a path refers to a network drive by mapped drive letter, all clients must use the same drive letter that the application uses. As an alternative, specify the server name in the path instead.

For example, both of these paths are valid when O: is mapped to \\marketing\drive. However, the second path that uses a server name is more likely to remain valid:

O:\pbapps\connect.bmp
\\marketing\drive\pbapps\connect.bmp