Skip to content

Programming with ActiveX Controls

The DataFlex Value Property and the ActiveX Control's Value

The DataFlex class library makes it easy to associate a single piece of data with a control in a concise way. For example, the Form class and the dbForm class associate the value in the Windows control with a Value property. The Form class contains two important properties that allow us to set and get the state of this data: get/set Value and get/set Item_Changed_State.

Using this interface allows you to work with this data even when the Windows control is not yet created (not yet activated), and it provides a consistent way to communicate with single value data objects.

Often, you will want to associate an ActiveX control with a single data value in the same way. For example, the calendar control is a single value data control containing a single date as its data.

Binding using ControlValue and ControlValueChanged

As a DataFlex programmer, you want to be able to synchronize the DataFlex Value property with an ActiveX control's "value" property. To do this, you'll need to find the messages in the control that get and set its data value and "bind" these properties to the DataFlex Value property of its wrapper class. This is accomplished by creating the methods Get ControlValue and Set ControlValue. These methods should be written to get and set the ActiveX control's real value property.

The name of this real value property is defined by the ActiveX control and could be any name. For example, the Calendar control's real value property happens to be called ComValue, so the code that must be created is:

Function ControlValue Returns String
    Function_Return (ComValue(Self))
End_Function

Procedure Set ControlValue String sVal
    Set ComValue to sVal
End_Procedure

See ControlValue for more information.

You may also need to identify the 'change event' in the ActiveX control and make it send OnControlValueChanged to tell DataFlex that the control's value changed.

For example, the CodeJock DateTimePicker control's change event property happens to be called OnComChange, so the code that must be created is:

Procedure OnComChange
    Send OnControlValueChanged
End_Procedure

See OnControlValueChanged for more information on doing so.

Automatic Binding

Many ActiveX controls publish information about their bindable property. In these cases, the FlexCOM class generator will use this information to create the necessary ControlValue interface automatically. When this occurs, your ActiveX control is automatically bindable, allowing you to use the DataFlex get/set Value syntax to work with this object; i.e., you do not have to write your own get/set ControlValue methods.

You can look inside the package generated when you import an ActiveX control for Function ControlValue and Procedure Set ControlValue to check if the binding has been done automatically or not.

Using the wrapper class's Value interface also means you do not have to worry about whether the COM control is actually created yet. You can set the Value property of an ActiveX wrapper object before that object connects with the underlying ActiveX control. The DataFlex wrapper class handles all of this for you. This can be an important feature because many ActiveX controls will automatically release themselves while they are not paged.

Data Aware Binding

If an ActiveX control is bindable, you can import the class and use it as a data aware entry object (a DEO) without any extra coding. This ability lets you automatically bind an ActiveX control with a field from a Data Dictionary Object. This is a powerful feature. As an example, you can see how data aware binding is used in the cComDbCalendar class in the COM Samples workspace:

Object oOrderCalendar is a cComDbCalendar
    Entry_Item Orderhea.Order_date
    Set Size to 140 140
    Set Location to 1 1
End_Object // oOrderCalendar

There are two points to note about this example:

  1. The Entry_Item command is all that is required to bind this control to the order_date field of the serving data dictionary object.
  2. All of this code is maintained automatically by the Studio using the Object Properties dialog. This is just like any other data aware DataFlex control, such as dbForm or dbEdit.

If a class is not automatically bindable, you will either need to create the binding yourself, or, more likely, binding just doesn't make sense for that class (for example, a Web-Browser ActiveX control has no bindable property). You would use these controls in a different manner.

Situations may arise where a control is bindable but you do not want to use the control in that manner. In this case, you can just ignore the binding mechanism and everything should work perfectly—you just would not use the get/set Value interface. If for some reason, the class binding behavior gets in your way, you can disable all binding and synchronization by setting the property pbBindValue to False (by default it is True). Setting pbBindValue to False severs any connection between the get/set Value message and any of the ActiveX control's interfaces. You will probably never need to change this property.

Aggregate ActiveX Controls

Many ActiveX controls are outer containers for a whole structure of COM objects. This is known in COM as aggregation. The inner objects of an aggregate ActiveX control will be implemented as Automation objects or, in other cases, collections of Automation objects.

Refer to Aggregate Objects in the Programming with Automation Objects section for details on accessing aggregate objects and aggregate collections.

See Also