OnCreateControl - cCJMenuItem

Event that is called when the COM control is created

Type: Event

Parameters: Handle hoObj

ParameterDescription
hoObjhandle of a proxy object bound to the COM control


Syntax
Procedure OnCreateControl Handle hoObj

Description

OnCreateControl is called when the COM control is created. This event can be used to set COM properties that could not be set by the object's standard (non-COM) properties.

It is passed a proxy object bound to the new COM control. The class of this object is determined by calling ClassForControlType, which specifies a class based on the control's type. This is done to ensure that the proper COM interfaces are available for use in this event. You should not destroy this object.

When a commandbar system is activated, the entire menu, toolbar and statusbar system is created. COM objects are created for each item's action and control. Typically a cCJMenuItem, a sub-class of cCJAction, is used to create both the action and the control. The action is created first by calling CreateComAction, which calls OnCreateAction. The control is created next by calling CreateComControl, which calls OnCreateControl. The entire process occurs within and is described in CreateComInstance.

Once a COM action is created it remains bound to the DataFlex proxy object until the commandbar system is deactivated or until the DataFlex object is destroyed. The COM control is not statically bound to a proxy object. If you need to send messages to the control's COM object you must create a proxy object, bind it, use it and destroy it. The exception to that rule occurs in OnCreateControl. The bound proxy object is passed. It is very important to understand that the proxy object passed is a temporary object. Before OnCreateControl is called, it is created and bound to the COM object. After the event is called, the proxy object is destroyed. The actual COM control objects should never be statically bound to DataFlex proxy object.

Most menu items will never require that you communicate directly with the COM control. The action interface (defined in cCJAction) provides all of the messages you need to handle the item. Some of the more complex controls, such as the combobox and edit controls, will require that you work with the control object. See cCJCommandBarComboBox for more information about using OnCreateControl to create combo lists. See cCJCommandBarEdit for more information about using OnCreateControl to set initial text in an edit.