Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - Access Violation using a custom form as a submenu
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Access Violation using a custom form as a submenu

 Post Reply Post Reply
Author
Message
MNovaro View Drop Down
Groupie
Groupie
Avatar

Joined: 20 June 2006
Status: Offline
Points: 71
Post Options Post Options   Thanks (0) Thanks(0)   Quote MNovaro Quote  Post ReplyReply Direct Link To This Post Topic: Access Violation using a custom form as a submenu
    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
 
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 06 July 2006 at 8:40am

Hello,

Please send sample to support@codejock.com

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
MNovaro View Drop Down
Groupie
Groupie
Avatar

Joined: 20 June 2006
Status: Offline
Points: 71
Post Options Post Options   Thanks (0) Thanks(0)   Quote MNovaro Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.