Skip to content

Combos, Edits and Other Complex Controls

The interface of the cCJMenuItem class provides an interface to access the most commonly needed properties of a menu/toolbar item. These common interfaces allow you to set captions, images, tooltips, etc. Some of the more complex controls will require that you interact directly with the COM control. Examples of this are combos and edit controls.

If you need to access the interface of a COM control, you need to:

  1. Create a proxy object.
  2. Bind the proxy object to the COM control.
  3. Use the interface that is unique to that object to interact with the control.
  4. Dispose of the proxy object when you are done.

All of the COM visual controls are automation objects. These steps are the standard steps you use to work with any COM automation with DataFlex. To use these with the command bar system, you need to be familiar with the COM control classes.

The Codejock implementation provides a number of specialized control classes that can be used for the different controls. Some of these classes are:

  • cCJCommandBarControl: This is the super-class of all command bar controls. It contains the basic interface for using any command bar control. This can be used by all controls.

  • cCJCommandBarPopup: This is a sub-class of cCJCommandBarControl and the class used for all popup classes. This can be used with popup (xtpControlPopup), button popup (xtpControlButtonPopup), and split-button popup (xtpControlSplitButtonPopup) peControlType objects.

  • cCJCommandBarButton: This is the class used for “button” menu and toolbar items. It can be used with normal buttons (xtpControlButton), checkboxes (xtpControlCheckBox), radios (xtpControlRadioButton), and labels (xtpControlLabel) peControlType objects.

  • cCJCommandBarComboBox: This is the class for combo control (xtpControlComboBox) peControlType objects.

  • cCJCommandBarEdit: This is the class for edit control (xtpControlEdit) peControlType objects.

When you bind a COM control to a proxy object, you must create the object based on the proper class. The following example shows how to bind to a combo and an edit.

// Create the combo proxy object
Get Create U_cCJCommandBarComboBox to hoCombo
// Bind the object to the COM dispatch pointer
Set pvComObject of hoCombo to vComboControl

// Create the edit proxy object
Get Create U_cCJCommandBarEdit to hoEdit
// Bind the object to the COM dispatch pointer
Set pvComObject of hoEdit to vEditControl

A helper function is provided that makes it easier to create and bind proxy objects. The CreateProxyControl function will create the object based on the appropriate class and bind it to the COM control in one step. It does the work of determining what the appropriate class is. The above sample is therefore simplified as shown below.

// Create the combo proxy object
Get CreateProxyControl vComboControl to hoCombo

// Create the edit proxy object
Get CreateProxyControl vEditControl to hoEdit

Normally, the COM dispatch pointer is known to you. It is passed to you in the events where you will need them, such as OnExecute or OnPopupInit. In this example, a combo’s OnExecute is called when the user selects a combo item. This will be used to create a bound combo proxy object. This is used as needed and then destroyed.

// This event is called when the combo menu item is selected.
Procedure OnExecute Variant vCommandBarControl
    Handle hMessage hoClient hoCombo
    Integer iIndex

    // Create a proxy object.
    Get CreateProxyControl vCommandBarControl to hoCombo

    // We can now use the interface in the COM control.
    Get ComListIndex of hoCombo to iIndex
    If (iIndex > 0) Begin
        Get ComItemData of hoCombo iIndex to hMessage
        If hMessage Begin
            Get Client_Id to hoClient
            Send hMessage to hoClient
        End
    End

    // When done, dispose of the proxy object
    Send Destroy of hoCombo
End_Procedure

For more information about working with combo controls, see cCJCommandBarComboBox.

In some cases, you will not know what the COM control’s dispatch pointer is. In such a case, you must search the command bar system for the control. You must find the control that has the same Id (ComId) as the menu/toolbar item’s action id (piId). The CreateFirstProxyControl function is provided to accomplish this. It finds the COM control object associated with the cCJMenuItem object and creates a proxy object for it.

The following example shows how you could get the value of an edit control’s text value from another object. We have an edit object and button on the same toolbar. When the button is selected, we want to get the edit control’s text value (ComText) and pass this in a RequestRun.

Object oEditMenuItem is a cCJMenuItem
    Set peControlType to xtpControlEdit

    Procedure OnCreateControl Handle hoObj
        // Note that OnCreateControl is passed the proxy object
        // already bound to the COM control. Therefore we don’t need to
        // create it or destroy it.
        // Set the initial value of the text
        Set ComText of hoObj to "test"
        Forward Send OnCreateControl hoObj
    End_Procedure
End_Object

Object oRunButton is a cCJMenuItem
    Set psCaption to "Run"

    Procedure OnExecute Variant vCommandBarControl
        Handle hoEdit
        String sText

        // Find the COM control that has the same action Id as the
        // oEditMenuItem’s action. We assume there will only be one
        // such control.
        Get CreateFirstProxyControl of oEditMenuItem to hoEdit
        If (hoEdit) Begin
            Get ComText of hoEdit to sText
            // When we are done with this, destroy it
            Send Destroy of hoEdit
        End
        Send RequestRun sText
    End_Procedure
End_Object

For more information about working with edit controls, see cCJCommandBarEdit.

See Also