Print Page | Close Window

Access Violation using a custom form as a submenu

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=4542
Printed Date: 21 June 2025 at 4:29am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Access Violation using a custom form as a submenu
Posted By: MNovaro
Subject: Access Violation using a custom form as a submenu
Date Posted: 06 July 2006 at 3:46am
Hello,

I found a bug in the CommandBars, using a custom form as a submenu item.

The problem is this:

- create a new VB6 project, with a MDI form in it
- create an MDI child, and add there a command bar object
- write this code in the MDI child, that generates a menu with a custom control in it, that uses a form (this is the same as your SDI sample code):

Set Control = .Add(xtpControlPopup, 0, "Find", -1, False)
Control.BeginGroup = True
Set ControlSearch = Control.CommandBar.Controls.Add(xtpControlCustom, ID_SEARCH_FORM, "Search Form", -1, False)
ControlSearch.Handle = crtlSearchForm.hWnd

- In the MDIForm_Unload event, write this code:

Private Sub MDIForm_Unload(Cancel As Integer)
    Dim frm As Form
    
    For Each frm In Forms
       
        Debug.Print frm.Name
       
        If frm.hWnd <> Me.hWnd Then
       
            Unload frm
       
        End If
       
    Next

End Sub

(I've got a project that simulates the problem, but I can't send it to the forum...)

Ok, now the problem is this: if you open the (custom) menu that contains the form, and then try to close the application, the MDIForm_Unload event generates an Acess Violation error, as soon as it tries to access "frm.Name". If you don't open the custom menu, this does not happens.
This happens only in an MDI environment (no problem using a SDI application).

Any idea on this?

Thanks for any help and kind regards,
Marco
 



Replies:
Posted By: Oleg
Date Posted: 06 July 2006 at 8:40am

Hello,

Please send sample to mailto:support@codejock.com - support@codejock.com



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: MNovaro
Date Posted: 06 July 2006 at 8:44am
Ok: I just posted my example application.
To test it, open the menu with the custom form, and then close the application (i.e. close the main MDI form)

Thanks for the support


Posted By: SuperMario
Date Posted: 10 July 2006 at 9:41am
Problem is you have commandbars on MDI child and you then try to unload the custom commandbars control is the MDI parent.

Add this to Form1 (form with commandbars):

Private Sub Form_Unload(Cancel As Integer)
  Dim Control As CommandBarControl
  Set Control = CommandBars.FindControl(, ID_SEARCH_FORM,,True)
  If Not Control Is Nothing Then
    Control.Delete
  End If
End Sub

Private Sub MDIForm_Unload(Cancel As Integer)
    Dim I As Long
    For I = Forms.Count - 1 To 1 Step -1
        Unload Forms(I)
    Next
End Sub



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net