How to add <PROPERTY> tag support to your ActiveForm

By: mykle hoban

Abstract: This article describes how to implement support for tags in your ActiveForm


How do I use <property> tags with my ActiveForm control?


This can be done by adding IPersistPropertyBag support to your ActiveForm. Normally, you would have to go through and actually implement the whole interface yourself, but the ATL is nice enough to provide a default implementation and a couple of handy macros. Here are the things we need to concern ourselves with:
IPersistPropertyBagImpl -- ATL's default IPersistPropertyBag implementation.
COM_INTERFACE_ENTRY_IMPL -- Tells the compiler that our class implements a certain interface. PROP_ENTRY -- Tells the compiler about a certain property of our class.

Adding property support to your ActiveForm (or any ActiveX control in BCB) is relatively simple. Our test ActiveForm is called AFormTest. The following additions are necessary (all of the code changes below are in your **Impl.h file.)

1) Add whatever properties you need in the Type Library Editor.
2) Note each property's DispID (this can be seen in the Attributes page of the TLE under ID).
3) Change the line:
  class ATL_NO_VTABLE TAFormTestImpl:
    VCLCONTROL_IMPL(TAFormTestImpl, AFormTest, TAFormTest, IAFormTest, DIID_IAFormTestEvents)
 To this:
  class ATL_NO_VTABLE TAFormTestImpl:
    VCLCONTROL_IMPL(TAFormTestImpl, AFormTest, TAFormTest, IAFormTest, DIID_IAFormTestEvents),
    public IPersistPropertyBagImpl<TAFormTestImpl>

4) Within the BEGIN..END_COM_MAP macros in your **Impl class, add the following:
5) Within the BEGIN..END_PROPERTY_MAP macros in your **Impl class, add the following:
  Where PropertyName is the name of your property, dispid is it's DispID, and CLSID_* is its CLSID.
5) Now implement your class's property getter/setters and it should work just fine!

Server Response from: ETNASC04