Bri*_*per 34 oop vb6 setter properties letter
我刚刚创建了几个Property Set方法,但它们没有编译.当我改变它们时Property Let,一切都很好.
因为我已经研究了文档,找到之间的区别Property Set和Property Let,但必须承认自己毫无收获.有没有什么区别,如果有的话,有人可以提供指向它的正确解释吗?
mwo*_*e02 29
Property Set 用于对象(例如,类实例)
Property Let 用于"正常"数据类型(例如,字符串,布尔值,长整数等)
wqw*_*wqw 24
Property Let比...更多才多艺Property Set.后者仅限于对象引用.如果你在课堂上有这个属性
Private m_oPicture As StdPicture
Property Get Picture() As StdPicture
Set Picture = m_oPicture
End Property
Property Set Picture(oValue As StdPicture)
Set m_oPicture = oValue
End Property
Property Let Picture(oValue As StdPicture)
Set m_oPicture = oValue
End Property
Run Code Online (Sandbox Code Playgroud)
您可以致电Property Set Picture与
Set oObj.Picture = Me.Picture
Run Code Online (Sandbox Code Playgroud)
您可以致电Property Let Picture与两个
Let oObj.Picture = Me.Picture
oObj.Picture = Me.Picture
Run Code Online (Sandbox Code Playgroud)
实现Property Set是其他开发人员期望的对象引用属性,但有时甚至Microsoft仅Property Let提供引用属性,从而导致不oObj.Object = MyObject带Set语句的不寻常语法.在这种情况下,using Set语句会导致编译时或运行时错误,因为类Property Set Object上没有实现oObj.
我倾向于同时实现Property Set与Property Let标准类型的属性-字体,图片等-但不同的语义.通常在Property Let我倾向于执行"深度复制",即克隆StdFont而不是仅仅持有对原始对象的引用.
| 归档时间: |
|
| 查看次数: |
47740 次 |
| 最近记录: |