Problem pre-processing MenuItem

Moderator: Rathinagiri

Post Reply
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Problem pre-processing MenuItem

Post 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...
[[]] Mauricio Ventura Faria
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Problem pre-processing MenuItem

Post 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
Luigi from Italy
www.L3W.it
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: Problem pre-processing MenuItem

Post 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
[[]]
[[]] Mauricio Ventura Faria
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: Problem pre-processing MenuItem

Post 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.
[[]] Mauricio Ventura Faria
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Problem pre-processing MenuItem

Post 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
Luigi from Italy
www.L3W.it
User avatar
concentra
Posts: 256
Joined: Fri Nov 26, 2010 11:31 am
Location: Piracicaba - Brasil

Re: Problem pre-processing MenuItem

Post 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.
[[]] Mauricio Ventura Faria
User avatar
l3whmg
Posts: 694
Joined: Mon Feb 23, 2009 8:46 pm
Location: Italy
Contact:

Re: Problem pre-processing MenuItem

Post 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
Luigi from Italy
www.L3W.it
Post Reply