on 2009 Jan 27 1:00 PM
Hi everybody,
i have a problem with the Context menu.
For a particular addon, i want to dynamically load a number of menus according to certain values in the mask of SAP, for example the CardCode or ItemCode.
After a certain number of rightclickmouse, "event where i do call a function that create a new menu", SAP show the messagge "
Error: Menu - Not found [66000-27]" or Menu - Already exists !!.
I also tried to create menus with xml files, but I always get errors.
I think there is some problem with the unreleased memory.
This is an example:
This is an example:
Private Function AddMenu(ByVal mnu As String, ByVal subMnu As String, ByVal title As String, _
ByVal pos As Integer, ByVal tipo As SAPbouiCOM.BoMenuType, _
ByVal pathImg As String) As Boolean
Try
Dim mnuItm As SAPbouiCOM.MenuItem = Nothing
Dim mnuItmNew As SAPbouiCOM.MenuItem = Nothing
Dim img As String = IO.Path.Combine(Application.StartupPath, pathImg)
If Not IO.File.Exists(img) Then img = ""
'Get father menu
mnuItm = SBO_Application.Menus.Item(mnu)
Dim oCreationPackage As SAPbouiCOM.MenuCreationParams
oCreationPackage = CType(SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_MenuCreationParams), SAPbouiCOM.MenuCreationParams)
With oCreationPackage
.Type = tipo
.UniqueID = subMnu
.String = title
.Enabled = True
.Checked = False
.Position = pos
End With
'Create new sub menu
If mnuItm.SubMenus IsNot Nothing AndAlso mnuItm.SubMenus.Exists(subMnu) Then
mnuItm.SubMenus.RemoveEx(subMnu)
End If
mnuItmNew = mnuItm.SubMenus.AddEx(oCreationPackage)
System.Runtime.InteropServices.Marshal.ReleaseComObject(mnuItm)
System.Runtime.InteropServices.Marshal.ReleaseComObject(mnuItmNew)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oCreationPackage)
GC.Collect()
Return True
Catch ex As Exception
SBO_Application.MessageBox("Error: " & ex.Message)
Return False
End Try
End Function
Public Sub New()
MyBase.New()
SetApplication()
End Sub
Private Sub SBO_Application_RightClickEvent(ByRef eventInfo As SAPbouiCOM.ContextMenuInfo, ByRef BubbleEvent As Boolean) Handles SBO_Application.RightClickEvent
If eventInfo.BeforeAction Then
'1^ level
AddMenu("1280", "MYMENU_01", "My Main Menu", 1, SAPbouiCOM.BoMenuType.mt_POPUP, "")
'2^ level
AddMenu("MYMENU_01", "MYMENU_11", "Menu 1.1.0", 1, SAPbouiCOM.BoMenuType.mt_POPUP, "")
For i As Integer = 0 To 10
AddMenu("MYMENU_01", "MYMENU_1" & i.ToString, "Menu 1." & i.ToString & ".0", i, SAPbouiCOM.BoMenuType.mt_POPUP, "")
'3^ level
For j As Integer = 0 To 4
AddMenu("MYMENU_1" & i.ToString, "MYMENU_1" & i.ToString & j.ToString, "Menu 1." & i.ToString & ".1", 1, SAPbouiCOM.BoMenuType.mt_STRING, "")
Next
Next
Else
If SBO_Application.Menus.Exists("MYMENU_01") Then SBO_Application.Menus.RemoveEx("MYMENU_01")
End If
End Sub
Thanks in Advance.
Hi,
Check if the Menu Already Exsists then remove it and Add it.
i.e. Before Addtion of the menu...check and remove it
like....
if (oMenus.Exists("M_EMPID"))
{
oMenus.RemoveEx("M_EMPID");
}
oMenus.AddEx(oCreationPackage);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
112 | |
8 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.