vb 变量声明Public Property Get 和Public Property let的 区别
如标题所示,这两个都是声明变量,但是我在一个程序中看到这样一段代码:
Public Property Get Locked(RowIndex As Integer, ColIndex As Integer) As Boolean
Locked = a_RowColLock(ColIndex, RowIndex)
End Property
Public Property Let Locked(RowIndex As Integer, ColIndex As Integer, blnLock As Boolean)
With m_MsFlexGrid_Pack
a_RowColLock(ColIndex, RowIndex) = blnLock
End With
End Property
谁能给我解释一下这两个函数的区别?
这两个函数名字一样,在什么情况下用的是get定义的这个 Locked函数,什么情况下用的是另一个?
[解决办法]
Locked 是类的属性。
Property Let 是用户设置属性。
Property Get 是用户读取属性。
[解决办法]
Dim c As Class1 '假定这就是你的类名Dim b As BooleanSet c = New Class1'下面这个属性赋值调用 Property Let,如果类中没有 Property Let,下面语句出错,即属性是只读的。c.Locked(1,1) = True'下面这个属性取值调用 Property Get,如果类中没有 Property Get,下面语句出错,即属性是不可读取的。b = c.Locked(1,1)
[解决办法]