Results 1 to 7 of 7

Thread: Dynamic menus

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Sydney, Aust
    Posts
    4

    Unhappy Dynamic menus

    Hi,

    I'm writing a VB.NET component dll to dynamically build menus from a database. This functions fine. A form contains the menu, and I assume should also contain the delegate event handler to handle the clicks on the dynamic menu and then call the component dll again sending which menu item was clicked. My problem is this... how do I assign the delegate as the handler for all the menu items created in the dll? So far I've assumed that I could pass the delegate as an object and use the AddressOf() function during the MenuItems.Add() to assign the delegate as the event handler. Any help would be appreciated.

    Adrian

  2. #2
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    It will look something like the following pseudo-code
    Code:
    Dim menuItem as new MenuItem()
    'your code here
    AddHandler(address of 'delegate here)
    Menu.Add(menuItem)
    \m/\m/

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Sydney, Aust
    Posts
    4

    thanx

    Thank you for your timely response.

    The code you mentioned to AddHandler will be in the dll and the delegate sub which will be referenced in this dll code example will be in a separate form that calls the dll. Do you know how I can pass this delegate or reference to it, to the dll?

  4. #4
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    you could pass the delegate as any other type.

    (I dont know if i understood your question correctly)
    \m/\m/

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Sydney, Aust
    Posts
    4

    clarification

    Yeah it's pretty hard to get my point across. I'll try a code example.

    Form Code:
    ---------------

    Call privObjUVConnection.LoadDynamicMenu(strExe, "frm3200", frmMain.mnuMain, frmMain)

    sub MenuHandler()...

    DLL Code:
    -------------

    Public Sub LoadDynamicMenu(ByVal strEXEName As String, ByVal strFormName As String, ByVal mnuMenu As Menu, ByVal frmForm As Object)

    mnuItems(intCnt) = New MenuItem(strMenuCaption, New System.EventHandler(AddressOf frmForm.MenuHandler))

    Points:
    ---------

    I'd like to reference MenuHandler() in the dll using the AddressOf() function to describe it as THE event handler for all dynamically created menus. No matter how I try, I get errors in the IDE stating it cant make the reference. This dll code needs to be reusable from any form that calls it.

    I'm not sure if I'm doing this the right way, or I'm missing something. I'm expecting that I cant pass over a reference/pointer or object that the dll can resolve the MenuHandler subroutine and apply it as the generic EventHandler so that the calling form will automatically call the dll with an index when a menu is clicked.

    Thanks for your time.


  6. #6
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Why not have the delegate in the DLL?

    You could add the handler to a sub inside the dll, and raise an event from there. All the user has to do is dim the dll withevents.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2004
    Location
    Sydney, Aust
    Posts
    4

    Done, thanx

    Menus now working. Thank you fo the support.

    Adrian

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width