Using OCX Controls in ProcScript

Uniface uses COM to invoke methods and properties of the OCX control in ProcScript. The $ocxhandle and $fieldproperties ProcScript functions can be used to invoke methods and set OCX properties.

  1. To use OCX methods in ProcScript:
    1. Define a field, parameter, or variable as type handle to store the OCX handle.

      It is good practice to use a component variable, because it has the same scope as the OCX object.

    2. Instantiate the OCX control.

      The OCX object can be instantiated only after the form on which it is drawn is instantiated and executes a show, edit or display statement. The handle to the OCX object is then available. You can use this handle to activate the public methods of the OCX control. The handle to the OCX control is destroyed if the instance of the form in which it lives is deleted.

    3. Use the $ocxhandle ProcScript function to get the handle and assign it to the variable.

      You can use $ocxhandle more than once without degrading performance, because the handle is cached internally.

    4. Use the handle to invoke the methods of the OCX object

      The following example shows how to get the handle of an OCX object and use it to invoke one of the OCX object's methods:

      operation exec
        ;$myOcxHandle$ is component variable of type Public Handle
        show
      
        $myOCXHandle$ = $ocxhandle("MY_OCX_FIELD.MY_ENTITY")
        if (status = -1)
           message/error "$ocxhandle is unable to retrieve the instance handle"
        endif
        $myOCXHandle$->SET_AUTOPLAY("true")
        edit
      end; exec
  2. To set the dynamic properties of the OCX container widget in ProcScript:
    1. Create an associated list of the physical names of dynamic properties and their values, of the properties you want to modify.
    2. Use the $fieldproperties ProcScript function to assign the list to the field properties of the field.

      The following examples show how to set the dynamic properties of the OCX container widget:

      • ChangeEvent is the physical name of an OCX container widget property and Change is the name of an OCX event.
        $fieldproperties("MY_OCX_FIELD.MY_ENTITY") = "ChangeEvent=Change"
      • DEFAULTKEYS stipulates that all keys are redirected to, and processed by, Uniface, rather than by the OCX. By default, all keys are passed to the OCX for processing, except for the keys listed in this property.
        $fieldproperties("MY_OCX_FIELD.MY_ENTITY") = "UNIFACEKEYS=DEFAULTKEYS"

        Note:  Some OCX controls have a keyboard hook installed, which means that certain key combinations cannot be redirected to Uniface, but are always processed by the OCX control. On the other hand, there are also some OCX controls, such as the rich edit control, where Ctrl+Z always causes Zoom within Uniface, rather than Undo within the OCX control.

      • You can specify individual keys to be redirected to Uniface; enter the keys as a comma-separated list. Key modifiers (Shift, Alt, and Control) can be connected to keys with the plus (+), minus (-), or space character. Keys and modifiers are case-insensitive and have the same spelling as those in the .ini file, for example, ‘Alt’ and ‘Ctrl’.
        $fieldproperties("MY_OCX_FIELD.MY_ENTITY") = "UNIFACEKEYS=Tab,Ctrl+A;FRAME=TRUE"

Related Topics