[Gambas-user] Problem with code made menu event handling

Fabien Bodard gambas.fr at ...626...
Sun Oct 7 10:13:15 CEST 2012


Oups yes ... It's not the good answer

Hmenuitem can be only local... In your case it contain the last created
menu . Thats why it use the last item properties .

In the event use LAST at the place of hMenuitem. and all will go fine.

Last represent the last fired menu.. in fact its the class or control that
have raised the event
Regards,
Le 7 oct. 2012 10:06, "Fabien Bodard" <gambas.fr at ...626...> a écrit :

> Have you try without the underscore in the event handler name ?
> Le 7 oct. 2012 09:52, "Tobias Boege" <taboege at ...626...> a écrit :
>
>> > > With 1 AddOn in the file (lets say AddOnOne) the menu shows AddOnOne
>> and
>> > > when clicking runs the application AddOnOne
>> > >
>> > > With 2 AddOns in the file (lets say AddOnOne and AddOnTwo) the menu
>> > > shows AddOnOne and AddOnTwo and When clicking either one of them
>> > > AddOnTwo is ALWAYS run.
>> > >
>> > > This somehow makes sense to me looking at my code.
>> >
>> > See my notes in your code as to why.
>> >
>> > > But how do I determine what menu item is clicked
>> >
>> > This is the real problem. Actually, I don't know if there is a way. This
>> > is also the reason that I used that addinmeta class. It essentially acts
>> > as a wrapper for the native Menu class and handles its' own events (via
>> > that SELF observer.  That way each addinmeta instance handles itself and
>> > "knows" what has been clicked.
>> >
>> > Doing this in a module as you have done maybe feasible but I found it
>> > easier to take the above approach.
>> >
>> >
>> > >     For iNdex = 1 To AddOnNumber
>> > >       hMenuItem = New Menu(hMenu) As "_MenuEvent"
>> > >       With hMenuItem
>> > >         .Name = "mnu" & AddOnName[iNdex]
>> > >         .Enabled = True
>> > >         .Caption = AddOnName[iNdex]
>> > >         .Text = AddOnName[iNdex] & "..."
>> > >       End With
>> > >     Next
>> > >   Endif
>> > >   If hMenu.Children.Count = 0 Then
>> > >     hMenu.Visible = False
>> > >   Endif
>> > >
>> > >
>> > > End
>> > >
>> > > Public Sub _MenuEvent_Click()
>> > >
>> > >   Dim iX, iLength As Integer
>> > >   Dim AddOnToRun As String
>> >
>> > When this is run, hMenuItem will be the last item you added, therefore
>> > no matter how many Add-Ins you load only the last one will be run.
>> > So you would need to find the menu item that was clicked and set
>> > hMenuItem to that.
>> >
>> > >   iLength = Len(hMenuItem.Caption)
>> > >   AddOnToRun = Left$(hMenuItem.Caption, (iLength - 3))
>> > >   AddOnToRun = AddOnToRun & ".gambas"
>> > >   Message(AddOnToRun)
>> > >   AddOns.Run(AddOnToRun)
>> > >
>> > > End
>>
>> Couldn't you use 'Last' instead of hMenuItem in _MenuEvent_Click()?
>>
>> Regards,
>> Tobi
>>
>>
>> ------------------------------------------------------------------------------
>> Don't let slow site performance ruin your business. Deploy New Relic APM
>> Deploy New Relic app performance management and know exactly
>> what is happening inside your Ruby, Python, PHP, Java, and .NET app
>> Try New Relic at no cost today and get our sweet Data Nerd shirt too!
>> http://p.sf.net/sfu/newrelic-dev2dev
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>>
>



More information about the User mailing list