persisting objects in ActiveX control propertybags 
Author Message
 persisting objects in ActiveX control propertybags


I've created an ActiveX control in VB6, say MyControl, that contains, as a
property, a collection class (i.e. my own class that wraps a Collection
object).  Let's call it CCol.  That class, in turn, manages a series of
specific node objects, say CNode's, that are used by the control to keep
track of sub-properties.  This is similar to the way in which VB's Toolbar
control keeps track of its toolbar buttons, and how the Statusbar control
manages its panels.

The control itself works as expected when the user/client/developer sets up
its properties in code (such as in the Form_Load() event).  However, like
VB's Toolbar and Statusbar controls (and the like), I need to allow the
developer to configure the control's properties -- its collection of nodes,
included -- at design-time via property pages.  The property pages I've
developed do provide a framework for such, in that the developer can scroll
through the ActiveX control's collection of nodes and set the individual
properties of each accordingly in a visual manner.

Unfortunately, I cannot seem to find a reliable way to persist or depersist
the control's collection object property (or the sub-property nodes of that
collection class property) to the parent form's .frm file, a process
normally made very easy for regular simple/native data type properties like
String, Integer, etc., by way of reading or writing to the control's
provided PropertyBag object in the control's ReadProperties() and
WriteProperties() events.

I use the following syntax to write the parent Collection object property to
the ActiveX control's PropertyBag (in the control's WriteProperties()
event): [assuming no default values for the properties]

 PropBag.WriteProperty "TotalNodes", m_oCollectionClass.Count
 PropBag.WriteProperty "CollectionClass", m_oCollectionClass

I then implement persistence for the collection class itself (CCol), and
insert the following syntax into its WriteProperties() event, which is fired
as a result of the call above: [assuming no default values for the

 Dim nCnt As Integer
 For nCnt = 1 to m_oAllNodes.Count 'm_oAllNodes is the inner Collection
class that is wrapped by CCol
  PropBag.WriteProperty "Node" & Str(nCnt), m_oAllNodes(nCnt)
 Next nCnt

Finally, I also implement persistence in the ground-level CNode class.  Its
WriteProperties() event, which is triggered by the call to WriteProperty()
of the collection class's PropertyBag object above, looks similar to this:
[assuming no default values for the properties]

 PropBag.WriteProperty "Name", m_sName
 PropBag.WriteProperty "Size", m_nSize
 PropBag.WriteProperty "Activated", m_bActivated

I can see that, at what seems to be random, this chain of persistence will
work properly.  The parent form (frmTest.frm, for example) of the ActiveX
control will, indeed, contain control attribute entries similar to this (as
is expected):


 Begin MyProject.MyControl TestControl1
        Left            =   240
  Top             =   4920
        _ExtentX        =   1005
  _ExtentY        =   1005
  BeginProperty CollectionClass {B7135552-850A-101B-AFC0-4210102A8DA7}
          TotalNodes      =   3
           BeginProperty Node1 {B713H354-850-101B-AFC0-4211116A8DA7}
              Name =   "Node-A"
              Size        =   40
              Activated   =   0 ' False
           BeginProperty Node2 {B713H354-850-101B-AFC0-4211116A8DA7}
              Name =   "Node-B"
              Size        =   23
              Activated   =   -1 ' True
           BeginProperty Node3 {B713H354-850-101B-AFC0-4211116A8DA7}
              Name =   "Node-C"
              Size        =   56
              Activated   =   0 ' False


However, like I said, the action is only random.  Sometimes when I run the
container form of the control, the control will properly persist its
collection state.  Other times, it simply won't.

Further, I cannot seem to find a way to actually read (i.e. depersist) the
collection object (and its underlying collection of node objects) back from
the propertybag once the collection object has been properly persisted.  For
example, when I try to do something like this (in the parent form's
ReadProperties event):

 Set Me.CollectionClass = PropBag.ReadProperty("CollectionClass")

I keep getting a run-time error stating "Object required".  Yet all of the
examples I've seen in MSDN indicate that this method for depersisting
objects from a propertybag does work.  In fact, I also tried this method to
persist/depersist an object in a non-ActiveX control project, and I did not
receive the error.  Unfortunately, although I received no error, the
propertybag refused to actually fill my object (in ReadProperties()) with
any data from its stored object, either.

I know I've presented a lot of information here, and perhaps from reading
it, everyone else may now be just as confused as I am.  I cannot seem to
find any real documentation *anywhere* on how to persist objects (let alone
collection classes) to and from propertybags in VB -- particularly within
ActiveX controls.  I would sincerely appreciate any help anyone can offer.

Thank you very much.

Mon, 09 Sep 2002 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. RESUBMISSION - persisting objects in ActiveX control propertybag

2. persisting objects in ActiveX control propertybag

3. Persisting ActiveX Control Information

4. ActiveX Conrol Propertybag and Recordsets

5. Removing ActiveX Control and other ActiveX objects from the registry

6. Accessing activex control from another activex object in ie5 (vb 6)

7. Duplicate keys allowed with VB PropertyBag object ???

8. Duplicate keys allowed with VB PropertyBag object ???

9. Problem storing object in PropertyBag

10. VB5 PropertyBag object only working at design time

11. Using Propertybag object to carry data over network

12. Duplicate keys allowed with VB PropertyBag object ???


Powered by phpBB® Forum Software