SPONSORS:






User Tag List

Results 1 to 4 of 4
  1. #1
    Junior Member
    Join Date
    Apr 2002
    Posts
    7
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Polymorphism with MenuItems

    Hi all,

    I ve declared a general Monitor Class that has a file menu like this:

    winclass MonitorClass : MainWin
    Menu File
    tag "File"
    MenuItem OpenBook
    MenuItem SaveBook


    Then I created a sub classe:

    winclass MyMonitorClass : MonitorClass
    Menu File
    tag "File"
    MenuItem NewPosition

    I then instantiate the whole like this:

    window MyMonitorClass MyMonitor
    tag "Monitor*"


    And in a testcase i call

    MyMonitor.File.OpenBook.Pick()

    And i get a compilation error, as if OpenBook is not defined in MyMonitor.File

    Any Idease?

    Thanks a lot

    Chris

    ------------------

  2. #2
    Senior Member
    Join Date
    Aug 1999
    Location
    Cambridge, UK
    Posts
    470
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Polymorphism with MenuItems

    Your problem is that you are trying to access the menuitem OpenBook defined under the menu File in the MonitorClass winclass; unfortunately you redefined the File menu in the subclass MyMonitorClass; as far the window MyMonitor concerned, it has a File menu defined with one MenuItem, NewPosition, and no others.
    In order to get round problems like this, I have resorted to defining the menu under a different name in the subclass - e.g. calling it File2, with the tag "File". It's a fairly ugly hack, but it works pretty well, and I don't know of any other way around it.

    ------------------

  3. #3
    Senior Member
    Join Date
    Feb 2000
    Posts
    1,497
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Polymorphism with MenuItems

    Or just add the "MenuItem NewPosition" in the Monitor Class making it the container for all File menu items. After all, instances of Monitor class can't/won't use NewPosition.

    Or since you're replacing the File member in the derived class, just replicate the OpenBook, SaveBook menuitems and add NewPosition.


    John
    '

    ------------------

  4. #4
    Senior Member
    Join Date
    Dec 2001
    Location
    Bozeman, MT, USA
    Posts
    265
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Polymorphism with MenuItems

    Hmm, I think he is shooting for using monitor class as a base object and then he wants to overload it. Here is what you need to do.

    You want to create your base menu as a class in itself. So you would basically have this:

    I dont know if you need the winclass MonitorClass anymore but I figured you probly had some other stuff in there.

    After doing that you will be able to compile and now be allowed to run

    ------------------
    Ryan McCullough
    RightNow Tech. Inc.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 09:13 AM.

Copyright BetaSoft Inc.