Skip to Content
0
Former Member
Jan 27, 2009 at 01:00 PM

I have a problem with some contextual menu loaded dynamically through sdk

82 Views

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.