Private Sub UserControl_WriteProperties(ByRef PBag As PropertyBag)
Dim Index1 as Integer,Index2 as Integer
With PBag
'First save the Parent class properties
.WriteProperty "Property1",Property1
.
.WriteProperty "Propertyn",Propertyn
'Then save the ChildClass1 collection object's number
.WriteProperty "ChildClass1Count",ChildClass1.Count
For Index1=1 To ChildClass1.Count
'Save the properties of each Object in the ChildClass1 Collection
.WriteProperty "ChildClass1[" & Index1 & "]Property1",ChildClass1(Index1).Property1
.
.WriteProperty "ChildClass1[" & Index1 & "]Propertyn",,ChildClass1(Index1).Propertyn
'Then save the ChildClass2 collection object's number of the current object in ChildClass1 collection
.WriteProperty "ChildClass1[" & Index1 & "].ChildClass2Count",ChildClass1(Index1).ChildClass2.Count
For Index2=1 To ChildClass2.Count
'Save the properties of each Object in the ChildClass2 Collection of the current object in ChildClass1 collection
.WriteProperty "ChildClass1[" & Index1 & "]ChildClass2[" & Index2 & "]Property1",ChildClass2(Index1).ChildClass2(Index2).Property1
.
.WriteProperty "ChildClass1[" & Index1 & "]ChildClass2[" & Index2 & "]Propertyn",ChildClass1(Index1).ChildClass2(Index2).Propertyn
Next Index2
Next Index1
End With
End Sub
Private Sub UserControl_ReadProperties(ByRef PBag As PropertyBag)
Dim Index1 as Integer,Index2 as Integer
Dim Max1 as Integer, Max2 as Integer
Dim oCCO1 as ChildClassObject1,oCCO2 as ChildClassObject2
With PBag
'First read the Parent class properties
Property1=.ReadProperty("Property1")
.
Propertyn=.ReadProperty("Propertyn")
'Then get the ChildClass1 collection object's number into Max1 variable
Max1=.ReadProperty("ChildClass1Count")
'Clears the ChildClass1 properties
Set ChildClass1=Nothing
Set ChildClass1 = New ChildClass1
For Index1=1 To Max1
'Create a object contained in ChildClass1 Collection
Set oCCO1=New ChildClassObject1
'Reads its properties
oCCO1.Property1=.ReadProperty("ChildClass1[" & Index1 & "]Property1")
.
oCCO1.Propertyn=.ReadProperty("ChildClass1[" & Index1 & "]Propertyn")
'Then get the ChildClass2 collection object's number for current object "oCCO1" into Max2 variable
Max2=.ReadProperty("ChildClass1[" & Index1 & "].ChildClass2Count")
'Clears the ChildClass2 collection inside oCCO1
Set oCCO1.ChildClass2=Nothing
Set oCCO1.ChildClass2=New ChildClass2
For Index2=1 To Max2
'Create a object contained in ChildClass2 Collection
Set oCCO2= New ChildClassObject2
'Reads its properties
oCCO2.Property1=.ReadProperty("ChildClass1[" & Index1 & "]ChildClass2[" & Index2 & "]Property1")
.
oCCO2.Propertyn=.ReadProperty("ChildClass1[" & Index1 & "]ChildClass2[" & Index2 & "]Propertyn")
'Save the object in ChildClass2 inside oCCO1
oCCO1.ChildClass2.AddObject oCCO2
Next Index2
'Save the object in ChildClass1
ChildClass1.AddObject oCCO1
Next Index1
End With
End Sub