很多老鸟都会写【类模块】,自己来创建【类】。
但是,很多时候很尴尬,经常性的要去修改旧有的类,增加或改变【类】的属性。当程序越写越大的时候,改变一个常用的【类】,将是一个非常巨大的工程。
考虑很久,我给我写的【类模块】加上一个万用的属性,随时可以扩展、修改。
它以一个词典为基础,添加一个Develop属性,具备任意扩展性! 属性值支持任意数据类型或对象。
--------------------代码---------------------------
Private DevelopDic_ As Scripting.Dictionary '扩展属性词典
Public Property Get Develop_Exists(Key As String) As Boolean '验证扩展属性是否存在
If DevelopDic_ Is Nothing Then Set DevelopDic_ = New Scripting.Dictionary
Develop_Exists = DevelopDic_.Exists(Key)
End Property
Public Property Get Develop(Key As String) '获取扩展属性
If Me.Develop_Exists(Key) = False Then GoTo Err1
On Error GoTo Next1
Set Develop = DevelopDic_.Item(Key)
Exit Property
Next1:
On Error GoTo Next2
Develop = DevelopDic_.Item(Key)
Exit Property
Next2:
On Error GoTo Err1
Develop = Null
Err1:
End Property
Public Property Let Develop(Key As String, Val As Variant) '属性赋值
If DevelopDic_ Is Nothing Then Set DevelopDic_ = New Scripting.Dictionary
DevelopDic_.Item(Key) = Val
End Property
Public Property Set Develop(Key As String, Obj As Object) '设置对象引用
If DevelopDic_ Is Nothing Then Set DevelopDic_ = New Scripting.Dictionary
Set DevelopDic_.Item(Key) = Obj
End Property