[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

Saving an object in PropBag

Within a UserControl, I want to use a self-made-object GColumns. This object has been compiled as an ActiveX-dll. Now I wish to save this GColumns-object in the PropertyBag of the UserControl, because I need the values which are stored in it. The values of the GColumns-object are filled at design-time.
This is the problem:
Using either PropBag.WriteProperties or PropBag.ReadProperties results in an runtime error: (-2147467262 "System Error &H80004002 Interface not supported").
I also tried to create the GColumns-object in the same project as the usercontrol, but this didn't work either.
The GColumns-object is not used as a property. This should not be a problem, because other variables can be stored in the PropBag easily. Other standard objects cannot be stored in the PropBag, so maybe I'm just having trouble finding the right way.
Hopefully someone has the brains to answer me.
0
VikiViking
Asked:
VikiViking
  • 5
  • 2
  • 2
1 Solution
 
VikiVikingAuthor Commented:
Edited text of question.
0
 
VikiVikingAuthor Commented:
Edited text of question.
0
 
VikiVikingAuthor Commented:
Adjusted points to 120
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
amebaCommented:
Dim pb As New PropertyBag
Dim oGColumns As GColumns
pb.WriteProperty "VIKI", oGColumns.object

Dim oGColumns As Object ' or GColumns
Set oGColumns = pb.ReadProperty("VIKI")

Be sure to check this in compiled version (not in IDE).
0
 
VikiVikingAuthor Commented:
Well, AMEBA, thanks for your answer, but this doesn't work for me. I've seen the code you've given me on MSDN, but I'm afraid that this is not going to work under VB5. It seems not to be possible to declare a variable as "New PropertyBag". Maybe it works with VB6. I haven't had the time to try this on another machine.
Furthermore, I used the compiled version (I didn't try that yet), but that gives the same error.
0
 
przemekCommented:
Try this:

Private Sub ReadPropertyGColumns(PropBag As PropertyBag)
    Dim gc As GColumns
    Dim i As Long
    Dim Name As String
   
    On Error Resume Next
    i = 1
    Do While (True)
        Name = PropBag.ReadProperty("gc" & CStr(i) & "Name", "")
        If (err.Number <> 0) Then Exit Do
        Set xf = m_colGColumns.Add(Name)
        gc.Prop1 = PropBag.ReadProperty("gc" & CStr(i) & "Prop1", "")
        gc.Prop2 = PropBag.ReadProperty("gc" & CStr(i) & "Prop2", "")
        i = i + 1
    Loop
    On Error GoTo 0
End Sub

Private Sub WritePropertyGColumns(PropBag As PropertyBag)
    Dim gc As GColumns
    Dim i As Long
   
    On Error Resume Next
    i = 1
    For Each gc In m_colGColumns
        Call PropBag.WriteProperty("gc" & CStr(i) & "Name", xf.Name)
        Call PropBag.WriteProperty("gc" & CStr(i) & "Prop1", xf.Prop1)
        Call PropBag.WriteProperty("gc" & CStr(i) & "Prop2", xf.Prop2)
        i = i + 1
    Next gc
    On Error GoTo 0
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Call ReadPropertyGColumns(PropBag)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call WritePropertyGColumns(PropBag)
End Sub

0
 
VikiVikingAuthor Commented:
Okay, przemek, I had been thinking of a solution like this, with the difference that I wanted to write it to some file. However, this is quite a job, because the GColumns-collection contains a lot of properties and one or more collections again. And the number of collections it contains is not constant.
So I'm afraid I just skip my search for this problem and try it with VB6 (still didn't have the time). Because I appreciate your proposed solution, I would like to give you the half of the points. Is that possible?

0
 
przemekCommented:
Thanks

I think it is not possible.
0
 
amebaCommented:
For VB5, in "Hardcore VB" there is a PropertyBagX object - but you are better with VB6.
0

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now