Page 1 of 1

Seperator in popupmenu

Posted: Thu Jan 04, 2018 3:59 pm
by ssg_mick
Hi,

i have a popupmenu containing 2 seperators.

Code: Select all

Procedure createContactPopupMenu()
  ContactPopupMenu = CreatePopupMenu(#PB_Any) 
  MenuItem(101, LANG_ShowCustomer.s)
  MenuItem(103, LANG_ShowNotes.s)
  MenuItem(104, LANG_ShowEmails.s)
  MenuItem(105, LANG_ShowTasks.s)
  MenuItem(106, LANG_ShowBranches.s)
  MenuItem(107, LANG_ShowOrders.s)
  MenuBar()
  MenuItem(109, LANG_CreateNote.s)
  MenuItem(110, LANG_CreateEmail.s)
  MenuItem(111, LANG_CreateTask.s)
  MenuItem(112, LANG_CreateBranch.s)
  MenuItem(113, LANG_CreateOrder.s)
  MenuBar()
  MenuItem(114, LANG_PhoneCall.s)
EndProcedure
But when i run my code, i get 3 seperators instead of one for every MenuBar().

Re: Seperator in popupmenu

Posted: Thu Jan 04, 2018 4:15 pm
by skywalk
Gap in your MenuItem() numbers? 102,108?

Re: Seperator in popupmenu

Posted: Thu Jan 04, 2018 5:29 pm
by wombats
The menu creation code you posted seems to work fine for me.

How are you using the createContactPopupMenu() function in your project? Are you recreating the menu each time it needs to be shown? Maybe you need to free it before recreating it.

Re: Seperator in popupmenu

Posted: Thu Jan 04, 2018 6:11 pm
by Marc56us
This can happen if one of the character strings (menu text) is empty.

ie: if LANG_PhoneCall.s = ""

:wink:

PS. Avoid using direct numbers as gadget ID, always use name or constant

Re: Seperator in popupmenu

Posted: Thu Jan 04, 2018 8:26 pm
by ssg_mick
wombats wrote:The menu creation code you posted seems to work fine for me.

How are you using the createContactPopupMenu() function in your project? Are you recreating the menu each time it needs to be shown? Maybe you need to free it before recreating it.
Yes, i create the PopupMenu every time when it should be shown. I wanted to try FreeGadget(ContactPopupMenu), but this only works, when it exists. How can i check, if a Gadget exists?

Re: Seperator in popupmenu

Posted: Thu Jan 04, 2018 8:29 pm
by davido
@ssg_mick,
May I suggest you look at: IsGadget().
Or, perhaps: IsMenu().

Re: Seperator in popupmenu

Posted: Thu Jan 04, 2018 8:33 pm
by ssg_mick
I tried this:

Code: Select all

 If IsGadget(#CustomerPopupMenu)
    FreeGadget(#CustomerPopupMenu)
  EndIf
but this did not solve the Problem.

Re: Seperator in popupmenu

Posted: Thu Jan 04, 2018 8:34 pm
by RASHAD

Code: Select all

Global ContactPopupMenu

Procedure createContactPopupMenu()
  If IsMenu(ContactPopupMenu)
    FreeMenu(ContactPopupMenu)
  EndIf
  ContactPopupMenu = CreatePopupMenu(#PB_Any)
  MenuItem(101, LANG_ShowCustomer.s)
  MenuItem(103, LANG_ShowNotes.s)
  MenuItem(104, LANG_ShowEmails.s)
  MenuItem(105, LANG_ShowTasks.s)
  MenuItem(106, LANG_ShowBranches.s)
  MenuItem(107, LANG_ShowOrders.s)
  MenuBar()
  MenuItem(109, LANG_CreateNote.s)
  MenuItem(110, LANG_CreateEmail.s)
  MenuItem(111, LANG_CreateTask.s)
  MenuItem(112, LANG_CreateBranch.s)
  MenuItem(113, LANG_CreateOrder.s)
  MenuBar()
  MenuItem(114, LANG_PhoneCall.s)
EndProcedure

Re: Seperator in popupmenu

Posted: Tue Jan 16, 2018 4:46 pm
by ssg_mick
Marc56us wrote:This can happen if one of the character strings (menu text) is empty.

ie: if LANG_PhoneCall.s = ""

:wink:

PS. Avoid using direct numbers as gadget ID, always use name or constant
This was my fault...

I had 2 MenuItems with empty Text$:

Code: Select all

Procedure createCustomerPopupMenu() 
  If CreatePopupMenu(#CustomerPopupMenu)
    MenuItem(#PopupMenuItemShowContacts, LANG_ShowContacts.s)
    MenuItem(#PopupMenuItemShowNotes, LANG_ShowNotes.s)
    MenuItem(#PopupMenuItemShowEmails, LANG_ShowEmails.s)
    MenuItem(#PopupMenuItemShowTasks, LANG_ShowTasks.s)
    ;MenuItem(#PopupMenuItemShowBranches, LANG_ShowBranches.s)
    ;MenuItem(#PopupMenuItemShowOrders, LANG_ShowOrders.s)
    MenuBar()
    MenuItem(#PopupMenuItemCreateContact, LANG_CreateContact.s)
    MenuItem(#PopupMenuItemCreateNote, LANG_CreateNote.s)
    MenuItem(#PopupMenuItemCreateEmail, LANG_CreateEmail.s)
    MenuItem(#PopupMenuItemCreateTask, LANG_CreateTask.s)
    ;MenuItem(#PopupMenuItemCreateBranch, LANG_CreateBranch.s)
    ;MenuItem(#PopupMenuItemCreateOrder, LANG_CreateOrder.s)
    MenuBar()
    MenuItem(#PopupMenuItemPhoneCall, LANG_PhoneCall.s)
  EndIf 
EndProcedure
Thanks all for your help and ideas.