Why is an event firing during compilation of a VB6 app?

后端 未结 2 1943
暗喜
暗喜 2020-12-19 06:44

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 ev

2条回答
  •  既然无缘
    2020-12-19 07:19

    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
    

提交回复
热议问题