Context information service

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.

Accessing context information

Using the context information service, you can access the information in Table 22-4.

Table 22-4: Context information

Item

Use this function

Comment

Full context name

GetName

Value returned depends on the context:

  • Default: PowerBuilder Runtime

  • Window plug-in: PowerBuilder window Plugin

  • Window ActiveX: PowerBuilder window ActiveX

Abbreviated context name

GetShortName

Value returned depends on the context:

  • Default: PBRUN

  • Window plug-in: PBWinPlugin

  • Window ActiveX: PBRTX

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)

Using the ClassName function

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:

StepsTo access context information:

  1. Declare an instance or global variable of type ContextInformation:

    ContextInformation icxinfo_base
    
  2. Create the context information service by calling the GetContextService function:

    this.GetContextService("ContextInformation", &
    
       icxinfo_base)
    
  3. 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
    

Accessing the ActiveX automation server

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:

For more information on the IWebBrowserApp interface, its methods, and its properties, see the Internet Explorer documentation or the Microsoft Web site.

StepsTo access the ActiveX automation server:

  1. Declare instance or global variables of type ContextInformation and OLEObject:

    ContextInformation   icxinfo_base
    
    OLEObject   iole_browser
    
  2. Create the context information service by calling the GetContextService function:

    GetContextService("ContextInformation",  &
       icxinfo_base)
    
  3. 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
    
  4. 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