Tip If you prefer working from a printed tutorial, see Copying and Printing in MSDN Library Help for details about printing a lesson, a set of topics, or a single topic.
Data binding is a powerful feature of ActiveX controls. Data binding is a notification mechanism that links control properties through the container to a data source, such as a database field. In this lesson, you will add a bindable property to the Circle control to illustrate simple data binding.
Note There is a difference between a bindable property and a bound property. Bindable refers to the fact that a property is available to be bound. A bindable property becomes a bound property at run time, when the control is created and inserted into a container that responds to bound property notifications.
There are two levels of data binding: optimistic and pessimistic. With optimistic data binding, the control assumes that changes can be made to a bound property; with pessimistic data binding, the control is required to ask the container's permission before making changes to the bound property. Whenever a bound property is changed, the control must notify the container by calling the appropriate function, depending on the level of data binding supported.
When optimistic data binding is used, the control notifies the container by calling the BoundPropertyChanged function. This form of data binding is used for the Note property in the Circle control.
When pessimistic data binding is used, the control requests permission from the container by calling the BoundPropertyRequestEdit function. If the BoundPropertyRequestEdit function returns TRUE, the control can change the bound property. However, if the BoundPropertyRequestEdit function returns FALSE, the control must not change the bound property.
Test Container's Notification Log dialog box helps you test bound properties that use either optimistic or pessimistic data binding. When the BoundPropertyChanged function is called, a notification is logged in the dialog box. You are also allowed to choose the response to each call to the BoundPropertyRequestEdit function. A different container might update a field in a database record when the BoundPropertyChanged function is called. It might also return FALSE from a call to the BoundPropertyRequestEdit function if the field or record was in use.
Note You can find a finished example of this lesson's code in the CIRC3 sample source code directory.
To clearly show the differences between bindable and nonbindable properties, a custom Get/Set property, called Note, will be implemented and changed into a bindable property in two separate steps.
In this lesson, you will: