Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

超级属性,任意【数据类型】与【对象】通用!

时 间:2020-07-06 08:25:08
作 者:litao   ID:37995  城市:上海
摘 要:给【类模块】添加一个超级属性,能任意扩展、改变!
一次添加,一次爽!
这次添加,无穷爽!
正 文:

很多老鸟都会写【类模块】,自己来创建【类】。
但是,很多时候很尴尬,经常性的要去修改旧有的类,增加或改变【类】的属性。当程序越写越大的时候,改变一个常用的【类】,将是一个非常巨大的工程。

考虑很久,我给我写的【类模块】加上一个万用的属性,随时可以扩展、修改。
它以一个词典为基础,添加一个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



Access软件网官方交流QQ群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助