为什么在编译VB6应用程序时发生事件? [英] Why is an event firing during compilation of a VB6 app?
问题描述
为什么会触发一个事件编辑过程中有什么办法阻止吗?
编辑:我有一些代码在这里,但并不相关。这个问题是由于UserControl代码(即Initialize,ReadProperties,Resize和WriteProperties事件)可以在意外的时间执行。如果这些事件中的代码依赖于其他代码来初始化其任何数据结构,那么很可能会失败,因为初始化代码可能未被执行。特别是在编译时,什么都不应该执行!我会把它称之为一个错误,但我确信微软可以以某种方式使其合理化。
这是一篇很好的文章用户控制事件的生命周期
这是一个片段
< blockquote>
编译项目
当项目编译成
应用程序或组件时,Visual Basic
加载所有表单文件不可见,
一个接一个,以便将
的信息写入
编译文件中。控件实例得到
Initialize,ReadProperties和
WriteProperties事件。控件的
属性设置被编译成
完成的可执行文件。
它没有提到resize在运行时发生,或者在设计时在容器上物理调整用户控件大小时)。可能您的Initialize事件正在调整用户控件的大小?
为了避免错误,您可以检查是否在执行任何操作之前创建了违规对象:
如果不是对象没有,那么
做某事
I am trying to compile a VB6 application, but it fails with the error, "Run-time error '91': Object variable or With block variable not set". It turns out the Resize event of a user control is firing during compilation and calling code that attempts to access an object that has not been instantiated yet.
Why is an event firing during compilation and is there any way to stop it?
Edit: I had some code here, but it's not relevant. The problem results from the fact that UserControl code (namely the Initialize, ReadProperties, Resize, and WriteProperties events) can execute at unexpected times. If the code in these events relies on other code to initialize any of its data structures, there's a good chance it's going to fail because that initialization code may not have executed. Especially during compilation when nothing is supposed to be executing! I'd call this a bug, but I'm sure Microsoft can rationalize it somehow.
Here's is a good article on the lifecyle of user control events
Understanding Control Lifetime and Key Events
Here is one snippet
Compiling the Project
When the project is compiled into an application or component, Visual Basic loads all the form files invisibly, one after another, in order to write the information they contain into the compiled file. A control instance gets the Initialize, ReadProperties, and WriteProperties events. The control's property settings are compiled into the finished executable.
It doesn't mention resize (which happens during run-time or when you physically resize the usercontrol on a container in design-time). Maybe your Initialize event is resizing the user control?
To avoid the error you can check if the offending object has been created before doing anything:
If Not Object Is Nothing then
do something
这篇关于为什么在编译VB6应用程序时发生事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!