![]() |
Access Violation using a custom form as a submenu |
Post Reply ![]() |
Author | |
MNovaro ![]() Groupie ![]() ![]() Joined: 20 June 2006 Status: Offline Points: 71 |
![]() ![]() ![]() ![]() ![]() 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 |
|
![]() |
|
Oleg ![]() Admin Group ![]() Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
![]() ![]() ![]() ![]() ![]() |
Hello, Please send sample to support@codejock.com |
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
MNovaro ![]() Groupie ![]() ![]() Joined: 20 June 2006 Status: Offline Points: 71 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
SuperMario ![]() Admin Group ![]() ![]() Joined: 14 February 2004 Status: Offline Points: 18057 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |