Forums

Find answers, ask questions, and connect with our
community all around the world.

Home Forum Omnis General Forum ‘vertical’ Scope of local variables and parameters

  • ‘vertical’ Scope of local variables and parameters

    Posted by Uwe Smidt on December 18, 2023 at 10:57 pm

    Dear $all,

    I would like to set up the ‘frame’ of a method $doThings in a super class (here the super table class taSuper), including local variables and parameters, and then specialize it in a sub class, e.g. taInvoices.$doThings, and do part of my calculations in the sub class’es inherited method, and then continue with Do inherited in the super class method.

    I was surprised to find that local variables that I defined in the super class method where not inherited down to the sub class method, and manipulations I did on the parameters in the sub class method where not maintained in the super class (e.g. parameter pValue=10 was passed to taInvoices.$doThings(10), then calculated pValue as 5 within the method, and when continuing after Do inherited, pValue was back to the initial pValue=10)

    Is this a bug or a feature, or what am I doing wrong or misconceiving?

    Thanx in advance!

    Uwe

    Uwe Smidt replied 2 months ago 3 Members · 3 Replies
  • 3 Replies
  • Dario L.

    Member
    December 19, 2023 at 8:28 am

    Hey,

    Unfortunately, Omnis can be a bit sketchy regarding method overloading and local variables management as you already know.

    However, there is a simple workaround. Instead of using the Do inherited command, write the sequent:

    Do $cinst.$inherited.$doThings(5) Returns #F
  • Andreas Pfeiffer

    Administrator
    December 19, 2023 at 8:51 am

    Hi Uwe,

    When you have an overridden method you can have the same parameter and the same value will be passed to the inherited method as well as its superclass method.

    If you want a different value you could use $cinst.$inherited.$myMethod() and pass a different value there. However I would be careful if you really want this.

    For example if you change the ID to be loaded in the inherited class your superclass will load a different record. Is this what you really want? If the behaviour is different I would rather suggest using another method and then call the other method from within there.

    Best,

    Andreas

  • Uwe Smidt

    Member
    December 19, 2023 at 4:31 pm

    Thank you guys 🙏!

    At least a work around.

    I helped myself with turning the local variables into instance variables. Works but is messy, dangerous & lacking elegance 💃…

Log in to reply.