Page 1 of 1
Problem pre-processing MenuItem
Posted: Mon Dec 12, 2011 5:31 pm
by concentra
There is a problem while pre-processing MenuItem using OOP syntax.
Try compile this :
Code: Select all
#include "hmg.ch"
FUNCTION Main()
LOCAL oWindow
DEFINE MAINWINDOW oWindow
Width 320
Height 400
WITH OBJECT MainMenu():New()
WITH OBJECT MenuPopup():New( ,, 'Test' )
MenuItem():New( 'oItem1',, 'Item 1' , { || MsgInfo( "Item 1" ) } )
MenuItem():New( 'oItem2',, 'Item 2' , { || MsgInfo( "Item 2" ) } )
END WITH
END WITH
END WINDOW
oWindow:Activate()
RETURN NIL
The pre-processor interprets this as XBase syntax and do a mess...
Re: Problem pre-processing MenuItem
Posted: Mon Dec 12, 2011 5:56 pm
by l3whmg
Hi Mauricio,
I'm sorry I re-edit my answer.... previous was ....wrong and unusefull
Instead MenuItem() please use
WITH OBJECT MenuItem..........; END WITH
Cheers
Re: Problem pre-processing MenuItem
Posted: Mon Dec 12, 2011 6:03 pm
by concentra
Hi Luigi !
The syntax mix was only a cut and paste in a test program...
The following code still don't work:
Code: Select all
#include "hmg.ch"
FUNCTION Main()
LOCAL oWindow
WITH OBJECT oWindow := MAINWINDOW():New()
:Width := 320
:Height := 400
WITH OBJECT MainMenu():New()
WITH OBJECT MenuPopup():New( ,, 'Test' )
MenuItem():New( 'oItem1',, 'Item 1' , { || MsgInfo( "Item 1" ) } )
MenuItem():New( 'oItem2',, 'Item 2' , { || MsgInfo( "Item 2" ) } )
END WITH
END WITH
END WITH
oWindow:Activate()
RETURN NIL
[[]]
Re: Problem pre-processing MenuItem
Posted: Mon Dec 12, 2011 6:17 pm
by concentra
l3whmg wrote:Hi Mauricio,
Instead MenuItem() please use
WITH OBJECT MenuItem..........; END WITH
This works Ok Luigi.
In fact the problem is that in .CH MENUITEM is a clause and is "translated" by preprocessor when it shouldn't.
the line
Code: Select all
MenuItem():New( 'oItem1',, 'Item 1' , { || MsgInfo( "Item 1" ) } )
Is preprocessed as
Code: Select all
With Object MENUITEM():New(,, ():New( "oItem1",, "Item 1" , { || MsgInfo( "Item 1" ) } ),,,, ) ; end
And if a var name is attributed with the menu item it preprocesses Ok, like in
Code: Select all
oItem1 := MenuItem():New( 'oItem1',, 'Item 1' , { || MsgInfo( "Item 1" ) } )
The solution seems to be remove the MENUITEM clauses from .CH and use only MENU ITEM ( with a space ) as XBase syntax.
Re: Problem pre-processing MenuItem
Posted: Mon Dec 12, 2011 7:36 pm
by l3whmg
Hi Mauricio
concentra wrote:In fact the problem is that in .CH MENUITEM is a clause and is "translated" by preprocessor when it shouldn't.
Obviously, because with HMG3 the command is "MENUITEM" and we must respect this rule. On the other hand I don't remember "MENU ITEM". I think it born with HMG4 but why?
concentra wrote:The solution seems to be remove the MENUITEM clauses from .CH and use only MENU ITEM ( with a space ) as XBase syntax.
Absolutely no: see previous answer. I think "MENU ITEM" must be removed.
On the other hand AFAIK with OOP the right/better syntax is
WITH OBJECT MenuItem():New(..... END WITH and not
MenuItem():New(.....
Cheers
Re: Problem pre-processing MenuItem
Posted: Tue Dec 13, 2011 10:32 am
by concentra
Hi Luigi.
l3whmg wrote:On the other hand I don't remember "MENU ITEM".
In my memory I think I was me...
I think it born with HMG4 but why?
Why not ? I use to write like this in other GUI.
Absolutely no: see previous answer.
So we must change the function name in order to avoid this preprocessor behavior.
On the other hand AFAIK with OOP the right/better syntax is WITH OBJECT MenuItem():New(..... END WITH and not MenuItem():New(.....
I see no problem with this syntax at all, but this is only my point of view.
By the way, in this line of code the object was attributed to a variable and I removed it because the compiler said that it was
assigned but never used.
Re: Problem pre-processing MenuItem
Posted: Tue Dec 13, 2011 11:48 am
by l3whmg
Hi Mauricio
concentra wrote:
l3whmg wrote:On the other hand I don't remember "MENU ITEM".
In my memory I think I was me..
Ok, now I know who
concentra wrote:
l3whmg wrote:I think it born with HMG4 but why?
Why not ? I use to write like this in other GUI.
.
Other GUI? Ok, now I know why.
IMHO: "HMG4 must follow HMG3 basis commands and when there isn't the command we must create a new one (or improve it with new options). In this situation, it is your personal need; i think you must create your personal include file (f.e. mycommands.ch)."
concentra wrote:
l3whmg wrote: Absolutely no: see previous answer.
So we must change the function name in order to avoid this preprocessor behavior.
I don't understand why do you need to change, sorry. See below.
concentra wrote:
l3whmg wrote:On the other hand AFAIK with OOP the right/better syntax is WITH OBJECT MenuItem():New(..... END WITH and not MenuItem():New(.....
I see no problem with this syntax at all, but this is only my point of view.
By the way, in this line of code the object was attributed to a variable and I removed it because the compiler said that it was assigned but never used.
IMHO: You can remove variable and don't assign anything like other objects in this way
Code: Select all
WITH OBJECT MainMenu():New()
WITH OBJECT MenuPopup():New( ,, 'Test' )
WITH OBJECT MenuItem():New( 'oItem1',, 'Item 1' , { || MsgInfo( "Item 1" ) } ) ; END WITH
WITH OBJECT MenuItem():New( 'oItem2',, 'Item 2' , { || MsgInfo( "Item 2" ) } ) ; END WITH
END WITH
END WITH
This is my humble opinion; I'm a volunteer, a contributor
Cheers