Simply tous need to store the menu instance in an array or a collection. Collection is usefully as you can retrieve menu from a name So in your form header Private $colMenu as new collection
In the menu creation: ... $colMenu[AddonName.index]=hmenu ... For delete $colMenu[AddonName.index] .delete $colMenu[AddonName.index]=NULL THAT'S ALL :-) Le 1 déc. 2012 05:22, "Willy Raets" <[email protected]> a écrit : > On Sat, 2012-12-01 at 11:00 +1030, Bruce wrote: > > On Sat, 2012-12-01 at 01:13 +0100, Willy Raets wrote: > > > I have this piece of code (in a rather big project) that build op a > menu > > > during run time in case AddOns get installed. Each installed AddOn gets > > > it own Menu Item upon installation for launching the AddOn. THis all > > > works like clockwork. > > > > > > This is the code that creates the menu items for each Add On installed: > > > > > > 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] & "..." > > > .Picture = Picture.Load(AddOnPath & "/" & AddOnName[iNdex] & > ".png") > > > End With > > > Next > > > > > > Now I write code to remove the installed AddOns if users want to. > > > Removing is no problem and works well. > > > > > > Only problem that remains is how to remove the menu item that starts > the > > > AddOn during run time? > > > > > > In my Subroutine Remove() the name of the AddOn menu item to be removed > > > is: "mnu" & AvailableName[Index] > > > > > > AvailableName[Index] is the name of the AddOn that has been removed a > > > few lines of code before. > > > > > > How do I remove this menu item? Any suggestions? > > > > > > Thanks, > > > > > > Willy > > > > > > > (Quick answer) > > You could just set its' .Visible to false > > Even better .Delete exists for menu items, but that isn't the problem. > > When I remove AddOn1 I need: mnuAddOn1.Delete (or .Visible = False) > When I remove AddOn2 I need: mnuAddOn2.Delete (or .Visible = False) > When I remove MyAddOn I need: mnuAddOn.Delete (or .Visible = False) > > Problem: > When removing AddOn1 when running the application the name of the menu > to remove "mnuAddOn1" is in a string variable > When removing AddOn2 when running the application the name of the menu > to remove "mnuAddOn2" is in a string variable > > How to tell Gambas that the String content is the name of the menu? > > Example: > > Dim sMenuNAme As String > sMenuName = "mnu" & AvailableName[Index] > > And now? I can't do: > > mnuAddOn1.Delete > > in my code as I don't know that it is named mnuAddOn1 at coding time > since that is determined during run time. AvailableName[Index] is the > name of the AddOn being removed at that time. > > Remember menus of add ons are made during runtime when the Addon is > installed and menu items are named "mnu" & AddOnName that just got > installed. Seemed logic at the time but not that sure anymore. > > Thanks anyway, > > Willy > > > > > ------------------------------------------------------------------------------ > Keep yourself connected to Go Parallel: > INSIGHTS What's next for parallel hardware, programming and related areas? > Interviews and blogs by thought leaders keep you ahead of the curve. > http://goparallel.sourceforge.net > _______________________________________________ > Gambas-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gambas-user > ------------------------------------------------------------------------------ Keep yourself connected to Go Parallel: INSIGHTS What's next for parallel hardware, programming and related areas? Interviews and blogs by thought leaders keep you ahead of the curve. http://goparallel.sourceforge.net _______________________________________________ Gambas-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gambas-user
