[Gambas-user] dynamic created Menus
Gianluigi
bagonergi at ...626...
Wed Feb 15 12:10:36 CET 2017
Hi Fabien,
let's see if I can clarify this.
In Gambas there are three different types of class:
- The real Class and its to be instantiated through the constructor (_new).
- The Form which is a class already instantiated, but can receive the
parameters which exposes the constructor (_new).
- The Module is a class already instantiated, and that does not expose the
constructor.
Therefore I can refer to a module with Me, I can use inside events and I
can even assign _new with another name to the module even if do not really
need.
I'm on the right track?
Regards
Gianluigi
2017-02-14 19:27 GMT+01:00 Gianluigi <bagonergi at ...626...>:
> But if it is static, because I can write this?
>
> Public Sub Form_Open()
>
> Dim foo As New MMenu
>
> foo.AddMenuFromModule(MenuCharacters)
>
> End
>
> I have trouble understanding
>
> Regards
> Gianluigi
>
> 2017-02-14 18:46 GMT+01:00 Fabien Bodard <gambas.fr at ...626...>:
>
>> A module is a class but static. Like i you declare all element of a
>> class as static
>>
>> 2017-02-14 17:02 GMT+01:00 Gianluigi <bagonergi at ...626...>:
>> > Hi all,
>> > first let me say that I do not want to teach anybody anything, I take
>> part
>> > in discussions to learn telling you what I think I know.
>> > If I gave a different impression I apologize, it's my poor English that
>> has
>> > struck again.
>> >
>> > And now the question, how is it that an event is in a module?
>> > See attached
>> >
>> > Thank you
>> > Gianluigi
>> >
>> > 2017-02-08 14:50 GMT+01:00 Gianluigi <bagonergi at ...626...>:
>> >
>> >> While should not, it work also in a Module.
>> >>
>> >> ' Gambas module file
>> >>
>> >> Public Sub AddMenuFromOutsideForm(hMenu As Menu)
>> >>
>> >> Dim hMenuItem As Object
>> >>
>> >> hMenuItem = New Menu(hMenu) As "mnCharacters"
>> >> hMenuItem.Text = "this don't work"
>> >> hMenuItem.Tag = "This do not work"
>> >> hMenuItem = New Menu(hMenu) As "mnCharacters"
>> >> hMenuItem.Text = "this also don't work'"
>> >> hMenuItem.Tag = "Also this do not work"
>> >>
>> >> End
>> >>
>> >> Public Sub mnCharacters_Click()
>> >>
>> >> Print Last.tag & " - " & Last.Text
>> >>
>> >> End
>> >>
>> >> 2017-02-08 14:25 GMT+01:00 Gianluigi <bagonergi at ...626...>:
>> >>
>> >>> Hi Karl,
>> >>>
>> >>> If you want to work with events, you should use a class.
>> >>> See attached example.
>> >>>
>> >>> Regards
>> >>>
>> >>> Gianluigi
>> >>>
>> >>> 2017-02-07 23:41 GMT+01:00 Karl Reinl <karl.reinl at ...9...>:
>> >>>
>> >>>> Am Montag, den 06.02.2017, 15:36 +0100 schrieb Fabien Bodard:
>> >>>> > I think the good way is this one :-)
>> >>>> >
>> >>>> > Public Sub AddMenuFromOutsideForm(hMenu As Menu)
>> >>>> > Dim hMenuItem As Object
>> >>>> > Dim hParent As Object = Object.Parent(hMenu)
>> >>>> >
>> >>>> > hMenuItem = New Menu(hMenu)
>> >>>> > hMenuItem = New Menu(hMenu)
>> >>>> > Object.Attach(hMenuItem, hParent, "mnu_this_dont_work")
>> >>>> > hMenuItem.Text = "this don't work"
>> >>>> > hMenuItem = New Menu(hMenu)
>> >>>> > Object.Attach(hMenuItem, hParent, "mnu_this_dont_work")
>> >>>> > hMenuItem.Text = "this also don't work'"
>> >>>> >
>> >>>> > End
>> >>>> >
>> >>>> >
>> >>>> > First find the class that handle menus events with object.parent on
>> >>>> > the given menu container.
>> >>>> >
>> >>>> > then attach the new menu events to the same class instance with
>> >>>> object.attach.
>> >>>> >
>> >>>> > 2017-02-06 15:08 GMT+01:00 Charlie Reinl <Karl.Reinl at ...9...>:
>> >>>> > > Salut,
>> >>>> > >
>> >>>> > > how can I use dynamic created Menus, when they are made outside
>> the
>> >>>> > > Form.
>> >>>> > > I expanded an example from Gianluigi to show what I want.
>> >>>> > > The problem is, the Click event is not fired, if the menu is not
>> >>>> created
>> >>>> > > in the forms class.
>> >>>> > >
>> >>>>
>> >>>> Salut,
>> >>>>
>> >>>> Fabien, gave me a solution for my problem. But I do not understand
>> why I
>> >>>> can attach Items to the menu, but not their events?
>> >>>> --
>> >>>> Amicalement
>> >>>> Charlie
>> >>>>
>> >>>>
>> >>>> ------------------------------------------------------------
>> >>>> ------------------
>> >>>> Check out the vibrant tech community on one of the world's most
>> >>>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> >>>> _______________________________________________
>> >>>> Gambas-user mailing list
>> >>>> Gambas-user at lists.sourceforge.net
>> >>>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >>>>
>> >>>
>> >>>
>> >>
>> >
>> > ------------------------------------------------------------
>> ------------------
>> > Check out the vibrant tech community on one of the world's most
>> > engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> > _______________________________________________
>> > Gambas-user mailing list
>> > Gambas-user at lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/gambas-user
>> >
>>
>>
>>
>> --
>> Fabien Bodard
>>
>> ------------------------------------------------------------
>> ------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>> _______________________________________________
>> 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