还有人发现他们在Access中的终止()方法没有被调用吗?
下面是我的cBusyPointer类的代码,为了简洁起见,删除了注释:
Option Compare Database ' Use database order for string comparisons
Option Explicit ' Declare EVERYTHING!
Option Base 1 ' Arrays start at 1
Public Sub show()
DoCmd.hourGlass True
End Sub
Private Sub Class_Terminate()
DoCmd.hourGlass False
End Sub典型用法是:
Sub doTehThings()
Dim hourGlass As New cBusyPointer
hourGlass.show()
' Do all teh things
End Sub在以前的版本中,每当对象超出作用域并被销毁时,该类将恢复沙漏。
我甚至试图手动销毁沙漏对象:
Sub doTehThings()
Dim hourGlass As cBusyPointer
Set hourGlass = New cBusyPointer
hourGlass.show()
' Do all teh things
Set hourGlass = Nothing
End Sub解决这一问题的唯一方法是添加隐藏()方法并调用该方法。
还有其他人遇到过这个问题吗?
发布于 2022-02-07 14:39:06
我不能重复这个问题。Terminate()方法在到达Set hourGlass = Nothing时被调用。
以下几点:
Dim hourGlass As New cBusyPointer这将在每次调用hourGlass变量时创建一个新实例,甚至将其设置为空。有关更多信息,请参见下面链接中的答案:
What's the difference between Dim As New vs Dim / Set
在处理对象时,应该始终使用Dim/Set。
hourGlass.show()这甚至不在VBA中编译。子类即使在需要参数时也不接受括号,除非它们前面有Call关键字。
最后,引用对象的最干净的方法是使用With语句访问对象,确保对象在到达End With语句时终止。
With New cBusyPointer
.show
End Withhttps://stackoverflow.com/questions/71014455
复制相似问题