在先前创建的 MultiPage 上调用 Add 时出现 VB6 Automation Error
VB6 Automation Error when calling Add on previously created MultiPage
我想生成一堆多页并在我的应用程序中动态创建新页面,但我收到 运行-time error '-2147417848 (80010108)': Automation error The object invoked has disconnected来自其客户。
重现步骤
在名为 TestClass 的 Class 模块中:
Public WithEvents TestMultiPage As MsForms.MultiPage
Sub createPage()
TestMultiPage.Add
End Sub
在名为 TestForm 的用户窗体中:
Dim TestInstances as New Collection
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X as Single, ByVal Y as Single)
If Button = fmButtonRight Then
Dim TestInstance as New TestClass
Set TestInstance.TestMultiPage = Me.Controls.Add("Forms.MultiPage.1")
TestInstances.Add TestInstance
End If
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim TestInstance As TestClass: Set TestInstance = TestInstances(1)
TestInstance.createPage
End Sub
当我右键单击用户窗体两次时,我得到两个多页。然后我双击用户窗体,希望第一个 MultiPage 有一个新的页面。但是我在 TestInstance.createPage
-> TestMultiPage.Add
处遇到了自动化错误,即使所有变量似乎都来自 Locals window。
我错过了什么?
结论
根据@GSerg 的回答,我想没有办法用 MultiPage 做到这一点。
相反,我必须改用 TabStrip 并模拟 MultiPage 的其他行为。
只是为了添加一些上下文,我试图创建一个类似浏览器的 UI,带有 windows 和选项卡(底部的 TabStrip 代表不同的 windows,每个 window 对应于具有多个选项卡的 MultiPage)。我在切换回之前的 MultiPage 并创建新选项卡时遇到了一个模糊的错误。
MSForms 中似乎存在问题,在添加新控件时,它会削弱现有的 MultiPage 控件。要重现问题,您不需要集合、数组、类,甚至不需要变量:
Sub Reproduce()
Me.Controls.Add "Forms.MultiPage.1", "TestInstance1"
Me.Controls("TestInstance1").Add ' That works
Me.Controls.Add "Forms.MultiPage.1", "TestInstance2"
Me.Controls("TestInstance1").Add ' Now it does not
Me.Controls("TestInstance2").Add ' But the new shiny one does
Me.Controls.Add "Forms.MultiPage.1", "TestInstance3"
Me.Controls("TestInstance2").Add ' Now the instance 2 is also defunct
Me.Controls("TestInstance3").Add ' Only the latest one works
End Sub
我不知道为什么会这样。它看起来像是 MSForms 中的错误。
否则控件工作正常,并且可以访问它们的属性,只是不能再调用 Add
。
我想生成一堆多页并在我的应用程序中动态创建新页面,但我收到 运行-time error '-2147417848 (80010108)': Automation error The object invoked has disconnected来自其客户。
重现步骤
在名为 TestClass 的 Class 模块中:
Public WithEvents TestMultiPage As MsForms.MultiPage
Sub createPage()
TestMultiPage.Add
End Sub
在名为 TestForm 的用户窗体中:
Dim TestInstances as New Collection
Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X as Single, ByVal Y as Single)
If Button = fmButtonRight Then
Dim TestInstance as New TestClass
Set TestInstance.TestMultiPage = Me.Controls.Add("Forms.MultiPage.1")
TestInstances.Add TestInstance
End If
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim TestInstance As TestClass: Set TestInstance = TestInstances(1)
TestInstance.createPage
End Sub
当我右键单击用户窗体两次时,我得到两个多页。然后我双击用户窗体,希望第一个 MultiPage 有一个新的页面。但是我在 TestInstance.createPage
-> TestMultiPage.Add
处遇到了自动化错误,即使所有变量似乎都来自 Locals window。
我错过了什么?
结论
根据@GSerg 的回答,我想没有办法用 MultiPage 做到这一点。 相反,我必须改用 TabStrip 并模拟 MultiPage 的其他行为。
只是为了添加一些上下文,我试图创建一个类似浏览器的 UI,带有 windows 和选项卡(底部的 TabStrip 代表不同的 windows,每个 window 对应于具有多个选项卡的 MultiPage)。我在切换回之前的 MultiPage 并创建新选项卡时遇到了一个模糊的错误。
MSForms 中似乎存在问题,在添加新控件时,它会削弱现有的 MultiPage 控件。要重现问题,您不需要集合、数组、类,甚至不需要变量:
Sub Reproduce()
Me.Controls.Add "Forms.MultiPage.1", "TestInstance1"
Me.Controls("TestInstance1").Add ' That works
Me.Controls.Add "Forms.MultiPage.1", "TestInstance2"
Me.Controls("TestInstance1").Add ' Now it does not
Me.Controls("TestInstance2").Add ' But the new shiny one does
Me.Controls.Add "Forms.MultiPage.1", "TestInstance3"
Me.Controls("TestInstance2").Add ' Now the instance 2 is also defunct
Me.Controls("TestInstance3").Add ' Only the latest one works
End Sub
我不知道为什么会这样。它看起来像是 MSForms 中的错误。
否则控件工作正常,并且可以访问它们的属性,只是不能再调用 Add
。