Creating an HTML page
After creating and building the PowerBuilder PBDs for your
PowerBuilder window ActiveX application, you need to create the
HTML page that displays it.
To include a PowerBuilder window on a Web page, you use the
Object element. Element attributes specify the class ID for the
PowerBuilder window ActiveX, the space allocated for the window,
the name of the PBD, the name of the child window in the PBD, the
library list, and the version of PowerBuilder.
A sample Object element might be:
|
1 |
<OBJECT NAME="PBRX1" WIDTH=225 HEIGHT=83 |
|
1 |
CLASSID="CLSID:BBBB1304-BBBB-1000-8000-080009AC61A9"> |
|
1 |
<PARAM NAME="_Version" VALUE="65536"></PARAM> |
|
1 |
<PARAM NAME="_ExtentX" VALUE="5962"></PARAM> |
|
1 |
<PARAM NAME="_ExtentY" VALUE="2164"></PARAM> |
|
1 |
<PARAM NAME="_StockProps" VALUE="0"></PARAM> |
|
1 |
<PARAM NAME="PBWindow" VALUE="w_helloworld"></PARAM> |
|
1 |
<PARAM NAME="LibList" VALUE="http://www.company.com/rknnt.pbd;"></PARAM> |
|
1 |
<PARAM NAME="PBApplication" VALUE="hello"></PARAM> |
|
1 |
<PARAM NAME="PBVersion" VALUE="100"></PARAM> |
|
1 |
</OBJECT> |
Attributes of the Object element
The Object element is part of the HTML specification for ActiveX
controls. It defines several standard attributes, and PowerBuilder
defines additional attributes.
HTML attributes
HTML attributes specify the class ID, the name, and the space
reserved for the PowerBuilder window ActiveX on the Web page.
| HTML attribute | Value | ||
|---|---|---|---|
| NAME | Name of the object when referenced in code or when submitted as part of a form. |
||
| CLASSID | The class ID of the registered ActiveX control. The syntax is:
To find the class ID value of the registered ActiveX control, you |
||
| CODEBASE | A URL identifying the location of the OCX or CAB file to be downloaded if the client machine does not contain the PowerBuilder window ActiveX. The client machine must still have the PowerBuilder virtual machine |
||
| WIDTH | The width of the viewing window in pixels. | ||
| HEIGHT | The height of the viewing window in pixels. |
The WIDTH and HEIGHT attributes define the maximum width and
height of the child window. If the child window is resizable, the
user can make it smaller than the specified size, but not larger.
Param elements
To specify properties for the PowerBuilder window ActiveX,
include Param elements. Param elements let you identify the window
object that starts your application, the Application object, additional
libraries, and additional parameters to pass to the PowerBuilder
window ActiveX. Table 34-3 lists
the PowerBuilder-specific Param elements.
| Property | Value |
|---|---|
| PBWINDOW | The class name of the child window in the PBD. |
| LIBLIST | A list of PowerBuilder dynamic libraries (PBD files) required by the application. Separate multiple entries with a semicolon. |
| PBAPPLICATION (optional) |
The PowerBuilder Application object. |
| PBVERSION | The version of the PowerBuilder DLLs (for example, 110). |
| DISPLAYERRORS (optional) |
Boolean indicating whether to display execution errors. |
| COMMANDPARM (optional) |
A string you want to pass to your window. To access this string from within your window, call the CommandParm function. |
Coding the Object element To minimize coding errors, use an ActiveX-aware HTML editor
(such as the JSP targets HTML editor, the ActiveX Control Pad, or
Front Page) when coding an Object element and its parameters.
Basic page
This sample page includes the PowerBuilder window ActiveX:

Here is the HTML code that produces this page (note the use
of the Object element to specify the PowerBuilder window ActiveX):
|
1 |
<HTML> |
|
1 |
<HEAD> |
|
1 |
<TITLE>Employee List</TITLE> |
|
1 |
</HEAD> |
|
1 |
<BODY> |
|
1 |
<H1>PowerBuilder window ActiveX</H1> |
|
1 |
<P> |
|
1 |
<OBJECT ID="PBRX1" NAME="PBRX1" WIDTH=357 HEIGHT=269 |
|
1 |
CLASSID="CLSID:BBBB1304-BBBB-1000-8000-080009AC61A9"> |
|
1 |
<PARAM NAME="_Version" VALUE="65536"> |
|
1 |
<PARAM NAME="_ExtentX" VALUE="9440"> |
|
1 |
<PARAM NAME="_ExtentY" VALUE="7112"> |
|
1 |
<PARAM NAME="_StockProps" VALUE="0"> |
|
1 |
<PARAM NAME="PBWindow" VALUE="w_emplist"> |
|
1 |
<PARAM NAME="LibList" VALUE="http://www.company.com/rknnt.pbd;"> |
|
1 |
<PARAM NAME="PBApplication" VALUE="rknnt"> |
|
1 |
<PARAM NAME="PBVersion" VALUE="110"> |
|
1 |
</OBJECT> |
|
1 |
</BODY> |
|
1 |
</HTML> |
Client-side scripting
You can interact with the window displayed in a PowerBuilder
window ActiveX by adding JavaScript or VBScript to the HTML page.
You can:
- Code event handlers that respond
to events that occur in the window - Call PowerScript functions to obtain pointer information,
print, set redraw, or set a timer - Call the InvokePBFunction function
to invoke a user-defined window function - Call the TriggerPBEvent function
to trigger a user event on the window
Viewing ActiveX properties, events, and functions When the window ActiveX is registered on your
machine, you can use the PowerBuilder Browser’s OLE tab
to see the list of window ActiveX properties, events, and functions.
Coding event handlers
Your HTML page can contain JavaScript or VBScript event handlers
for the PowerBuilder window ActiveX.
Coding example assumptions The following code examples assume that the HTML page includes
a Form, named buttonForm, which contains several Input elements:
passedFlags, passedXPos, and passedYPos.
To code JavaScript event handlers for the PowerBuilder
window ActiveX:
-
Insert the PowerBuilder window ActiveX
into the HTML page, specifying all necessary properties:1<OBJECT NAME="PBRX1" WIDTH=225 HEIGHT=831CLASSID="CLSID:BBBB1304-BBBB-1000-8000-080009AC61A9">1<PARAM NAME="_Version" VALUE="65536">1<PARAM NAME="_ExtentX" VALUE="5962">1<PARAM NAME="_ExtentY" VALUE="2164">1<PARAM NAME="_StockProps" VALUE="0">1<PARAM NAME="PBWindow" VALUE="w_helloworld">1<PARAM NAME="LibList" VALUE="http://www.company.com/rknnt.pbd;">1<PARAM NAME="PBApplication" VALUE="rknnt">1<PARAM NAME="PBVersion" VALUE="110">1</OBJECT> -
Within the heading of the HTML page, code a function
to be called when the event occurs.The following sample function simply displays the arguments
to the Clicked event.1function wasClicked(flags, xpos, ypos) {1document.buttonForm.passedFlags.value = flags;1document.buttonForm.passedXPos.value = xpos;1document.buttonForm.passedYPos.value = ypos;1} -
Within the body of the HTML page, code an event
handler that calls the function when the event occurs:1<SCRIPT LANGUAGE="JavaScript" FOR="PBRX1" Event="Clicked(flags, xpos, ypos)">1<!--1wasClicked(flags, xpos, ypos);1-->1</SCRIPT>
Coding style Alternatively, you can omit the function call, placing all
code within the event handler, as shown next.
To code VBScript event handlers for the PowerBuilder
window ActiveX:
-
Insert the PowerBuilder window ActiveX
into the HTML page, specifying all necessary properties:1<OBJECT NAME="PBRX1" WIDTH=225 HEIGHT=831CLASSID="CLSID:BBBB1304-BBBB-1000-8000-080009AC61A9">1<PARAM NAME="_Version" VALUE="65536">1<PARAM NAME="_ExtentX" VALUE="5962">1<PARAM NAME="_ExtentY" VALUE="2164">1<PARAM NAME="_StockProps" VALUE="0">1<PARAM NAME="PBWindow" VALUE="w_helloworld">1<PARAM NAME="LibList" VALUE="http://www.company.com/rknnt.pbd;">1<PARAM NAME="PBApplication" VALUE="rknnt">1<PARAM NAME="PBVersion" VALUE="110">1</OBJECT> -
Within the body of the HTML page, code an event
handler that processes the event.This sample function simply displays the arguments to the
Clicked event:1<SCRIPT LANGUAGE="VBScript">1<!--1Sub PBRX1_Clicked(flags, xpos, ypos)1document.buttonForm.passedFlags.value = flags1document.buttonForm.passedXPos.value = xpos1document.buttonForm.passedYPos.value = ypos1end sub1-->1</SCRIPT>
Calling PowerScript functions
The PowerBuilder window ActiveX allows you to call certain
PowerScript functions on the window displayed in the Active control:
- PointerX Returns the distance from the left edge of the window to the pointer.
- PointerY Returns the distance from the top of the window to the pointer.
- Print Prints the window.
- SetRedraw Turns on or off automatic redrawing of the window after every
change. - Timer Causes the window’s Timer event to occur repeatedly
at the specified interval.
For more information on these functions, see
the PowerScript Reference.
As with all ActiveX controls, the PowerBuilder window ActiveX
provides an AboutBox function, which you can
call to see information about the control.
Coding example assumptions The following coding examples assume that you have written
scripts to be invoked by the PowerBuilder window’s Timer
event.
To use JavaScript to call a PowerScript function:
-
Code a function to call the PowerScript
function.This example calls the PowerScript Timer function:
1<SCRIPT LANGUAGE="JavaScript">1<!--1var cumSeconds = 0;1function setPBTimer( f ) {1var li_return1var li_interval1li_interval = parseInt(f.timerInterval.value);1li_return = PBRX1.Timer(li_interval);1if (li_return != 1) {1alert("Set Timer failed");1}1}1//-->1/SCRIPT -
Code a function, anchor, or button that calls
the function.This example uses a button on a form to call the function
defined above, which resets the timer interval:1<FORM NAME="clockForm">1<P>Timer Interval:1<INPUT TYPE=Text NAME="timerInterval" Size="5">1<P><INPUT TYPE=BUTTON VALUE="Set Timer"1ONCLICK="setPBTimer(this.form)">1</FORM>
To use VBScript to call a PowerScript function:
-
Code a function to call the PowerScript
function. This example calls the PowerScript Timer function:1<SCRIPT LANGUAGE="VBScript">1<!--1dim cumSeconds1cumSeconds = 01Sub pbSetTime()1dim li_return1dim li_interval1li_interval = clockForm.timerInterval.value1li_return = pbrx1.Timer(li_interval)1if li_return 1 THEN1msgBox "Set Timer failed"1end if1end sub1//-->1</SCRIPT> -
Code a function, anchor, or button that calls
the function.This example uses a button on a form to call the function
defined above, which resets the timer interval:1<FORM NAME="clockForm">1<P>Timer Interval:1<INPUT TYPE=Text NAME="timerInterval" Size="5">1<HR>1<P>Mirror of PB Time:1<INPUT TYPE=Text NAME="pbTime" Size="8">1<HR>1<P>INPUT TYPE=BUTTON VALUE="Set Timer" onClick="call pbSetTime()">1</FORM>
Calling user-defined functions
The PowerBuilder window ActiveX provides the InvokePBFunction function, which
you can use to call a user-defined window function.
VBScript and JavaScript differ If your user-defined functions contain arguments and you are
using JavaScript, you must use SetArgElement to specify the arguments;
you cannot specify the arguments explicitly in the InvokePBFunction function.
To code JavaScript that invokes a user-defined
function:
-
Define window functions as needed.
The following example assumes that in the PowerBuilder window,
you have defined the function of_arg that
takes a string as a parameter. -
Code a JavaScript function that calls the InvokePBFunction function, specifying
the user-defined function to invoke.This example initializes arguments and calls the of_args window
function:1function invokeFunc(f) {1var retcd;1var rc;1var numargs;1var theFunc;1var theArg;1retcd = 0;1numargs = 1;1theArg = f.textToPB.value;1PBRX1.SetArgElement(1, theArg);1theFunc = "of_args";1retcd = PBRX1.InvokePBFunction(theFunc, numargs);1rc = parseInt(PBRX1.GetLastReturn());1if (rc != 1) {1alert("Error. Empty string.");1}1PBRX1.ResetArgElements();1} -
Code a function, anchor, or form button that invokes
your JavaScript function. For example:1<FORM>1<P>Copy this text to PowerBuilder:1<INPUT TYPE=Text NAME="textToPB" SIZE="20">1<P><INPUT TYPE=BUTTON VALUE="Invoke Func"1ONCLICK="invokeFunc(this.Form)">1</FORM>
Defining arguments in JavaScript When coding in JavaScript, define function and event arguments
by calling the SetArgElement function.
To code VBScript that invokes a user-defined function:
-
Define window functions as needed.
The following example assumes that in the PowerBuilder window
you have defined the function of_arg that
takes a string as a parameter. -
Code a VBScript function that calls the InvokePBFunction function, specifying
the user-defined function to invoke.This example initializes arguments and calls the of_args window
function:1Sub invokeFunction()1Dim retcd1Dim myForm1Dim args(1)1Dim rc1Dim numargs1Dim theFunc1Dim rcfromfunc1retcd = 01numargs = 11rc = 01theFunc = "of_args"1Set myForm = Document.buttonForm1args(0) = buttonForm.textToPB.value1retcd = PBRX1.InvokePBFunction(theFunc, <br /> numargs, args)1rc = PBRX1.GetLastReturn()1if rc 1 then1msgbox "Error. Empty string."1end if1PBRX1.ResetArgElements()1end sub -
Code a function, anchor, or form button whose
click invokes your VBScript function. For example:1<FORM NAME="buttonForm">1<P><INPUT TYPE=Text NAME="textToPB" SIZE="20">1<P><INPUT TYPE=BUTTON VALUE="Invoke Function" ONCLICK="call invokeFunction()">1</FORM>
Calling user events
The PowerBuilder window ActiveX provides the TriggerPBEvent function, which
you can use to call a user event on the window.
To code JavaScript that triggers a user event:
-
Define user events on the window as needed.
The following example assumes that in the PowerBuilder window
you have defined the user event ue_args that takes a string
as an argument. -
Code a function to call the user event. This example
initializes arguments and calls the ue_args window event:1function triggerEvent(f) {1var retcd;1var rc;1var numargs;1var theEvent;1var theArg;1retcd = 0;1numargs = 1;1theArg = f.textToPB.value;1PBRX1.SetArgElement(1, theArg);1theEvent = "ue_args";1retcd = PBRX1.TriggerPBEvent(theEvent, numargs);1rc = parseInt(PBRX1.GetLastReturn());1if (rc != 1) {1alert("Error. Empty string.");1}1PBRX1.ResetArgElements();1} -
Code a function, anchor, or form button that calls
the TriggerPBEvent function. For example:1<FORM>1<P><INPUT TYPE=Text NAME="textToPB" SIZE="20">1<P><INPUT TYPE=BUTTON VALUE="Trigger Event"1ONCLICK="triggerEvent(this.Form)">1</FORM>
To code VBScript that triggers a user event:
-
Define user events on the window, as needed.
The following example assumes that in the PowerBuilder window
you have defined the user event ue_args that takes a string
as an argument. -
Code a function to call the user event. This example
initializes arguments and calls the ue_args window function:1Sub TrigEvent( )1Dim retcd1Dim myForm1Dim args(1)1Dim rc1Dim numargs1Dim theEvent1retcd = 01numargs = 11rc = 01theEvent = "ue_args"1Set myForm = Document.buttonForm1args(0) = buttonForm.textToPB.value1retcd = PBRX1.TriggerPBEvent(theEvent,1numargs, args)1rc = PBRX1.GetLastReturn()1if rc 1 then1msgbox "Error. Empty string."1end if1PBRX1.ResetArgElements()1end sub -
Code a function, anchor, or form button whose
click invokes your VBScript function. For example:1<FORM NAME="buttonForm">1<P><INPUT TYPE=Text NAME="textToPB" SIZE="20">1<P><INPUT TYPE=BUTTON VALUE="Trigger Event" ONCLICK="call TrigEvent()">1</FORM>