I'm trying to learn the X++ language and I have one problem at the beginning.
I want to create a dynamic menu in a given window, i.e. without a visual menu generator. And I can't somehow assign the SubMenu to the main Menu item (menubar). What am I doing wrong?
The SubMenu will not appear
PARTIAL CLASS MyMenu INHERIT Menu
CONSTRUCTOR( oOwner )
SELF:PreInit()
LOCAL oSubMenu AS Menu
oSubMenu := Menu{}
oSubMenu:AppendItem(103,"&Open..." )
oSubMenu:AppendItem(104,"Print Setup...")
SELF:AppendItem(101,"&File")
SELF:AppendItem(102,"&Help")
SELF:AppendItem(0,oSubMenu)
SELF:PostInit()
RETURN
END CLASS
Thanks for your help.
Radim
I want to create a dynamic (sub)menu in a given window
Re: I want to create a dynamic (sub)menu in a given window
Hi Radim,
if you want to create dynamic menu entries, you need to register the item in the menu.
This is a part of code you need to add a dynamic item to a menu:
Adding a submenu to a menu you can call then the AppendItem() method:
Wolfgang
if you want to create dynamic menu entries, you need to register the item in the menu.
This is a part of code you need to add a dynamic item to a menu:
Code: Select all
method AddItem( nId, symmethod,cName,cDescription) class DynMenu
self:RegisterItem( nID, Hyperlabel{ symmethod,, cDescription,, } )
self:AppendItem( nID, cName )
return nil
Code: Select all
oMenu:AppendItem( oSubMenu, "File" )
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Re: I want to create a dynamic (sub)menu in a given window
Hi Wolfgang.
Thank for your reply.
My dynamic menu system is working now.
I have other question.
In code: self:RegisterItem( nID, Hyperlabel{ symmethod,, cDescription,, } ) is parameter "symmethod".
Yes, I can use method name #FileExit for example.
But, can I use in this parameter code block: eval(MyCodeBlock,param) for example ?
thanks.
Radim
Thank for your reply.
My dynamic menu system is working now.
I have other question.
In code: self:RegisterItem( nID, Hyperlabel{ symmethod,, cDescription,, } ) is parameter "symmethod".
Yes, I can use method name #FileExit for example.
But, can I use in this parameter code block: eval(MyCodeBlock,param) for example ?
thanks.
Radim
Re: I want to create a dynamic (sub)menu in a given window
Hi Radim,
the VO GUI classes are using name based linking in many cases, and one of them is the link of the method name to the menu name.
If you do not wish that because you are either generating dynamic names or don't like that, you can use the MenuCommand method of the owner window:
HTH
Wolfgang
the VO GUI classes are using name based linking in many cases, and one of them is the link of the method name to the menu name.
If you do not wish that because you are either generating dynamic names or don't like that, you can use the MenuCommand method of the owner window:
Code: Select all
method MenuCommand( oEvent ) class MyWindow
local oMenuEvent as MenuCommandEvent
local cName as string
oMenuEvent := oEvent
super:MenuCommand( oMenuEvent )
cName := oMenuEvent:Name
do case
case cName == "menuchoide1"
// ....
case cName == "menuchoide12"
// ....
endcase
return nil
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Re: I want to create a dynamic (sub)menu in a given window
Hi Wolfgang,
MenuCommand method is perfect.
Back to the self:RegisterItem( nID, Hyperlabel{ symmethod,, cDescription,, } )
Can I use: self:RegisterItem( nID, Hyperlabel{ #MyMethodName(cParam),, cDescription,, } )
Radim
MenuCommand method is perfect.
Back to the self:RegisterItem( nID, Hyperlabel{ symmethod,, cDescription,, } )
Can I use: self:RegisterItem( nID, Hyperlabel{ #MyMethodName(cParam),, cDescription,, } )
Radim
Re: I want to create a dynamic (sub)menu in a given window
Hi Radim,
sorry, I had not understood your question correctly.
A Hyperlabel requires a symbolic name, and not a codeblock or similar thing.
You can do something like this:
and then split that out in the MenuCommand method.
I'm doing that in several places in some of my applications specially when the menu is based on a number of files present in a folder or similar dynamic data.
Wolfgang
sorry, I had not understood your question correctly.
A Hyperlabel requires a symbolic name, and not a codeblock or similar thing.
You can do something like this:
Code: Select all
self:RegisterItem( nID, Hyperlabel{ "MyMethodName_" + cParam,, cDescription,, } )
I'm doing that in several places in some of my applications specially when the menu is based on a number of files present in a folder or similar dynamic data.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Re: I want to create a dynamic (sub)menu in a given window
self:RegisterItem( nID, Hyperlabel{ #DoSomething(cFile,.T.),, cDescription,, } )
METHOD DoSomething(cFileName, lReadOnly) class MyWindow
.................
RETURN SELF
METHOD DoSomething(cFileName, lReadOnly) class MyWindow
.................
RETURN SELF
Re: I want to create a dynamic (sub)menu in a given window
The Hyperlabel class expects a Symbol as first parameter.
So
is not allowed.
If you want to pass parameters to the method, I recommend that you create a parameter less event handler, and call the method from that event handler
Robert
So
Code: Select all
Hyperlabel{ #DoSomething(cFile,.T.)
If you want to pass parameters to the method, I recommend that you create a parameter less event handler, and call the method from that event handler
Code: Select all
self:RegisterItem( nID, Hyperlabel{ #SomethingEvent,, cDescription,, } )
.
.
.
METHOD SomethingEvent() class MyWindow
// retrieve cFile from class or other storage location
SELF:DoSomething(cFile, TRUE)
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu