[Gambas-user] Trouble removing menu item during run time

Willy Raets willy at ...2734...
Sat Dec 1 05:20:49 CET 2012


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






More information about the User mailing list