You use the context information service to obtain information about an application’s execution context. The service provides current version information, as well as whether the application is running in the PowerBuilder execution environment and whether as a PowerBuilder window plug-in or a PowerBuilder window ActiveX. Using this information, you can modify display characteristics and application behavior. For example, you might hide a Close command button when running as a plug-in or ActiveX. Additionally, when running in the PowerBuilder window ActiveX under Internet Explorer, the context information service can return a reference to an ActiveX automation server object. Your application can use this reference to call functions that control the Web browser.
Using the context information service, you can access the information in Table 22-4.
Item |
Use this function |
Comment |
---|---|---|
Full context name |
GetName |
Value returned depends on the context:
|
Abbreviated context name |
GetShortName |
Value returned depends on the context:
|
Company name |
GetCompanyName |
Returns Sybase, Inc. |
Version |
GetVersionName |
Returns the full version number (for example, 10.5.0.1) |
Major version |
GetMajorVersion |
Returns the major version number (for example, 10.5) |
Minor version |
GetMinorVersion |
Returns the minor version number (for example, 0) |
Fix version |
GetFixesVersion |
Returns the fix version number (for example, 1) |
You can also use the ClassName function to determine the context of the object. The return value of the ClassName function differs by context. For example, for the Window plug-in the return value is plugincontextinformation, and for the Window ActiveX it is rtxcontextinformation.
You can use this information for many purposes, including:
Modifying application appearance based on execution context For example, you might hide a Close button when running in the PowerBuilder window plug-in and PowerBuilder window ActiveX. In a plug-in or ActiveX, closing the window results in a blank space in the HTML page.
Verifying that the context supports the current version For example, if your application requires features or fixes from Version 10.5.0.1, you can use the context information service to check the version in the current execution context.
To access context information:
Declare an instance or global variable of type ContextInformation:
ContextInformation icxinfo_base
Create the context information service by calling the GetContextService function:
this.GetContextService("ContextInformation", &
icxinfo_base)
Call context information service functions as necessary.
This example calls the GetShortName function to determine the current context and the GetVersionName function to determine the current version:
String ls_name
String ls_version
Constant String ls_currver = "7.0.01"
icxinfo_base.GetShortName(ls_name)
IF ls_name <> "PBRun" THEN
cb_close.visible = FALSE
END IF
icxinfo_base.GetVersionName(ls_version)
IF ls_version <> ls_currver THEN
MessageBox("Error", &
"Must be at Version " + ls_currver)
END IF
If you are running the PowerBuilder window ActiveX in Internet Explorer Version 3.0 or later, your application can call the context information service’s GetHostObject function to obtain a reference to an ActiveX automation server object (the hosting object). Specifically, if you pass an uninstantiated OLEObject variable to GetHostObject, it returns a reference to the IWebBrowserApp automation server.
Your application can call and access IWebBrowserApp methods and properties, which allow you to access and control certain aspects of browser behavior, including:
Go back
Go forward
Go home
Refresh
Navigate to a specified Web page
Exit the browser
For more information on the IWebBrowserApp interface, its methods, and its properties, see the Internet Explorer documentation or the Microsoft Web site.
To access the ActiveX automation server:
Declare instance or global variables of type ContextInformation and OLEObject:
ContextInformation icxinfo_base
OLEObject iole_browser
Create the context information service by calling the GetContextService function:
GetContextService("ContextInformation", & icxinfo_base)
Establish a reference to the ActiveX automation server by calling the GetHostObject function:
Integer li_rtrn
li_rtrn = icxinfo_base.GetHostObject(iole_browser)
IF li_rtrn = 1 THEN
sle_host.Text = "GetHostObject succeeded"
ELSE
sle_host.Text = "GetHostObject failed" END IF
Call IWebBrowserApp functions as necessary. This example calls the Navigate function to open the default Web browser displaying the Sybase home page:
IF IsValid(iole_browser) THEN
iole_browser.Navigate &
("http://www.sybase.com", 0, 0, 0)
END IF