我正在写一个ActiveX控件,我写了如下的属性:--------------------------------------------------------------------dim m_NormalImageList as ObjectPublic Property Get NormalImageList() As Object
    
    Set NormalImageList = m_NormalImageListEnd Property
Public Property Set NormalImageList(ByVal New_NormalImageList As Object)
    
    Set m_NormalImageList = New_NormalImageList
    
    PropertyChanged "NormalImageList"End Property--------------------------------------------------------------------
为了在从设计模式切换到运行模式时保持属性的值,我写了如下事件代码:--------------------------------------------------------------------Private Sub UserControl_WriteProperties(PropBag As PropertyBag)    Call PropBag.WriteProperty("NormalImageList", m_NormalImageList, Nothing)
    
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)    Set m_NormalImageList = PropBag.ReadProperty("NormalImageList", Nothing)End Sub--------------------------------------------------------------------我觉得一切都合理,可是在我调试的时候,这一句:Call PropBag.WriteProperty("NormalImageList", m_NormalImageList, Nothing)出现了错误:非法的参数。
很郁闷啊,请会这个的朋友指导我一下吧。

解决方案 »

  1.   

    保存到properybag的对象要求能够持久化。
      

  2.   

    不能保存 object,转换成具体的基本类型才能,例如 byte()/string/integer等之类的
      

  3.   

    原来不能保存object类型,那我想问:我的控件里有一个属性,这个属性是用来选择窗体上的其他控件,就像在ToolBar控件里面,可以选择几个ImageList控件一样。像这样的属性怎么做出来呢?谁能写个样子给我吗?
      

  4.   

    通常的做法是保存控件的名字,运行时根据名字去找控件。如:' 以下在 UserControl 内
    Private Function getCtlByName(ByVal CtlName As String)
        
        Dim c   As Control
        Dim cs  As Object
        
        CtlName = UCase(CtlName)
        
        Set cs = Parent.Controls
        
        For Each c In cs
            If UCase(c.Name) = CtlName Then
                Set getCtlByName = c
                Exit For
            End If
        Next
        
    End Function