超级属性,任意【数据类型】与【对象】通用!-litao
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


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

发表时间:2020/7/6 8:25:08 评论(0) 浏览(2833)  评论 | 加入收藏 | 复制
   
摘 要:给【类模块】添加一个超级属性,能任意扩展、改变!
一次添加,一次爽!
这次添加,无穷爽!
正 文:
很多老鸟都会写【类模块】,自己来创建【类】。
但是,很多时候很尴尬,经常性的要去修改旧有的类,增加或改变【类】的属性。当程序越写越大的时候,改变一个常用的【类】,将是一个非常巨大的工程。

考虑很久,我给我写的【类模块】加上一个万用的属性,随时可以扩展、修改。
它以一个词典为基础,添加一个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群(群号:198465573)
 
 相关文章
【Access小品】真是扯谈--类模块与标准模块  【煮江品茶  2014/9/26】
类模块实现登陆窗体+导航窗体  【lzk  2015/12/24】
类模块进度条(带运行时间,进度文本)  【lzk  2015/12/24】
怎样创建类模块  【杨雪  2016/9/27】
【Access编程技巧】怎样修改模块、类模块名称  【杨雪  2017/1/7】
玩玩高大上的类模块  【爱吉瑞  2019/10/5】
常见问答
技术分类
相关资源
文章搜索
关于作者

litao

文章分类

文章存档

友情链接