读书人

请大家帮小弟我看看出错的原因吧

发布时间: 2012-03-03 15:33:03 作者: rapoo

请大家帮我看看出错的原因吧?


我正在写一个ActiveX控件,我写了如下的属性:

--------------------------------

dim m_NormalImageList as Object

Public Property Get NormalImageList() As Object

Set NormalImageList = m_NormalImageList

End 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)

出现了错误:非法的参数。


很郁闷啊,请会这个的朋友指导我一下吧。




[解决办法]
不能保存 object,转换成具体的基本类型才能,例如 byte()/string/integer等之类的
[解决办法]
通常的做法是保存控件的名字,运行时根据名字去找控件。如:

' 以下在 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

读书人网 >VB

热点推荐