VB6 Usercontrol gives access violation when handling events

From: simmonda (Andrew.Simmonds_at_vivista.co.uk.(donotspam))
Date: 01/18/05

  • Next message: Lewis Miller: "RE: how to convert from char * to string"
    Date: Tue, 18 Jan 2005 08:09:08 -0800
    
    

    Hi,

    I have been trying to track down a situation where the VB VM enters an
    endless loop when a form is unloaded. It appears that the VM is searching a
    list looking for a particular value (object?) with specific properties but is
    unable to find it.

    During that testing I found a situation where the VM generates an access
    violation when running under the VC++ debugger (memory is being filled with
    invalid values) but doesn't when running normally or under the VB IDE. This
    appears to be an access to a freed object by the VB runtime.

    Further investigations have led to the following very small project
    containing a form and two user controls:-

    Create usercontrol1 and add a label (caption "Double click me"); in the code
    add

    Public Event dblclick()

    private sub label1_dblclick()
       raiseevent dblclick
    end sub

    Create usercontrol2 and add an instance of usercontrol1; in the code add

    public event dblclick()

    private sub usercontrol11_dblclick()
        raiseevent dblclick
    end sub

    Finally add an instance of usercontrol2 to the form and add the following code

    private sub usercontrol21_dblclick()
        unload me
    end sub

    Compile this to a .exe and run it - all seems well. Attaching the VC++
    debugger to the app and re-starting it from within the debugger leads to the
    access violation.

    It appears that the problem manifests itself when events are bubbled through
    several 'nested' controls resulting in the form performing an Unload
    operation. Performing an unload without nesting of events does not exhibit
    the problem.

    Has anybody else come across the same or a similar problem and know what is
    happening please?

    My concern is that this issue when running normally leads to heap corruption
    or VBVM state corruption thus causing the endless loop in the VM. Any
    suggestions as to the cause of this would also be welcomed.

    I have reproduced the problem on several machines which are all running VB6
    SP5.

    Many thanks
    Andrew

    [Reposted due to reply address misunderstanding]


  • Next message: Lewis Miller: "RE: how to convert from char * to string"

    Relevant Pages

    • vb6 usercontrol gives access violation when handling events
      ... Public Event dblclick() ... private sub usercontrol11_dblclick ... several 'nested' controls resulting in the form performing an Unload ... or VBVM state corruption thus causing the endless loop in the VM. ...
      (microsoft.public.vb.bugs)
    • VB6 usercontrol gives access violation when handling events
      ... Public Event dblclick() ... private sub usercontrol11_dblclick ... thus causing the endless loop in the VM. ...
      (microsoft.public.vb.bugs)
    • Re: Open a sub form too last viewed record
      ... To test that idea, see if the table contains the correct data, for the last record viewed in the subforms before closing the form. ... the information about the current record may already be gone when the subform's Unload event fires. ... Set rst = db.OpenRecordset ... Private Sub Form_Unload ...
      (microsoft.public.access.forms)
    • Re: Floating Box for Prices
      ... Private Sub Form_DblClick ... I applied the above code to my chart program. ... Unload frmPricebox ... It is suppose to detect if the Pricebox form is open. ...
      (microsoft.public.vb.general.discussion)
    • Re: Open a sub form too last viewed record
      ... 'This is the unload code for the main form ... Set rst = db.OpenRecordset ... them from both your form and subform. ... Private Sub Form_Unload ...
      (microsoft.public.access.forms)

    Loading