Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Overriding a Function in a class... 10 Apr 2019 02:32 #8347

  • FoxProMatt
  • FoxProMatt's Avatar
  • Topic Author


  • Posts: 430
  • When you override a Function in X#, what is the code required to call the base function from your override, and may need to pass along parameters as well.

    Please Log in or Create an account to join the conversation.

    Overriding a Function in a class... 10 Apr 2019 04:03 #8348

    • Chris
    • Chris's Avatar


  • Posts: 3652
  • Depending on in which dll the function is defined:

    XSharp.RT.Functions.<function name>
    XSharp.VO.Functions.<function name>
    XSharp.Core.Functions.<function name>

    for example XSharp.RT.Functions.AAdd()
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Overriding a Function in a class... 10 Apr 2019 04:39 #8350

    • FoxProMatt
    • FoxProMatt's Avatar
    • Topic Author


  • Posts: 430
  • I should have been more clear in stating that I want to override a Function or Method inside of a Class definition and call the base method from my override.


    In C#, overriding a method and calling its base code looks like this:
    class B : A
    {
      override void X() { 
        base.X();
        Console.WriteLine("y"); 
      }
    }

    I’m trying to understand how to do this same type of construct in X#

    Please Log in or Create an account to join the conversation.

    Last edit: by FoxProMatt.

    Overriding a Function in a class... 10 Apr 2019 05:37 #8351

    • lumberjack
    • lumberjack's Avatar


  • Posts: 714
  • Hi Matt,

    FoxProMatt_MattSlay wrote: I should have been more clear in stating that I want to override a Function or Method inside of a Class definition and call the base method from my override.
    In C#, overriding a method and calling its base code looks like this:

    class B : A
    {
      override void X() { 
        base.X();
        Console.WriteLine("y"); 
      }
    }
    I’m trying to understand how to do this same type of construct in X#

    And from what Chris said:

    Depending on in which dll the function is defined:

    XSharp.RT.Functions.<function name>
    XSharp.VO.Functions.<function name>
    XSharp.Core.Functions.<function name>
    for example XSharp.RT.Functions.AAdd()

    begin namespace XSharp.RT.VFP
    static partial class Functions
        static method AAdd() as void
            XSharp.RT.Functions.AAdd()
            Console.Writeline("y")
        return
    end class
    end namespace
    Or if you want to keep the Functional look of it:
    begin namespace XSharp.RT.VFP
        function AAdd() as void
            XSharp.RT.Functions.AAdd()
            Console.Writeline("y")
        return
    end namespace
    Ok this was quick and out of the top of my head, hopefully Chris or somebody will chirp in to show the exact details where I went wrong, but this is the basic concept.

    HTH,
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Last edit: by lumberjack.

    Overriding a Function in a class... 10 Apr 2019 05:49 #8352

    • Jamal
    • Jamal's Avatar


  • Posts: 297
  • Maybe like the following:
    CLASS B INHERIT A
    OVERRIDE METHOD X() AS VOID
         SUPER:X()
         Console.WriteLine("y") 
    RETURN

    Please Log in or Create an account to join the conversation.

    Last edit: by Jamal.

    Overriding a Function in a class... 10 Apr 2019 14:41 #8358

    • Chris
    • Chris's Avatar


  • Posts: 3652
  • Matt, just in case this wasn't clear, due to mine and Johan's misunderstanding on what you were asking, it's what Jamal mentioned what you're looking for, the use of "SUPER:" to call a method of a parent class.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Overriding a Function in a class... 10 Apr 2019 21:13 #8369

    • FoxProMatt
    • FoxProMatt's Avatar
    • Topic Author


  • Posts: 430
  • Yes. Indeed his answer with Super:X() was exactly what I was looking for.

    Please Log in or Create an account to join the conversation.

    Overriding a Function in a class... 11 Apr 2019 08:16 #8371

    • lumberjack
    • lumberjack's Avatar


  • Posts: 714
  • Hi Matt,

    FoxProMatt_MattSlay wrote: Yes. Indeed his answer with Super:X() was exactly what I was looking for.

    Yes that is the short answer. Also look at what I said, I was assuming you want to "override" a X# function, with same name as in VFP, but with totally different behavior, or some extended behavior. Will also have the same effect as SUPER:X(), but with a "Functional" approach.
    begin namespace XSharp.RT.VFP
    static partial class Functions
        static method AAdd() as void
            XSharp.RT.Functions.AAdd() // This is same behavior as SUPER:AAdd()
            Console.Writeline("y") // We extended our method/function with a "Method" approach
        return
    end class
    end namespace
    Or if you want to keep the Functional look of it:
    begin namespace XSharp.RT.VFP
        function AAdd() as void
            XSharp.RT.Functions.AAdd() // Again same behavior as SUPER:AAdd()
            Console.Writeline("y") // Same extended functionality, using a functional approach
        return
    end namespace
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Overriding a Function in a class... 11 Apr 2019 17:15 #8374

    • FoxProMatt
    • FoxProMatt's Avatar
    • Topic Author


  • Posts: 430
  • Something that has to be considered is sublclasses of subclasses...

    If you just call: XSharp.RT.Functions.AAdd() , then if you are 3 level deep in subclassing, then you will skip the other levels of the inherited classes and juMP straight to the lowest level that you are basically hard-coding to.

    Whereas, if you use Super() at each subclass along the way, you can rest assured that you are not skipping another essential code in the immediate parent class.

    I'm sure there could be a time when one *wanted* to have this effect, bu they way I code most of my multi-level inherited classes, I will use Super() to be sure each layer gets called.

    Please Log in or Create an account to join the conversation.

    Last edit: by FoxProMatt.

    Overriding a Function in a class... 11 Apr 2019 18:02 #8377

    • Chris
    • Chris's Avatar


  • Posts: 3652
  • Calling XSharp.RT.Functions.AAdd() has absolutely nothing to do with subclassing, I mentioned it only because I misinterpreted your term "override".

    The issue is that DotNet has no concept of functions (in the sense that they live "outside" of a class), so they are implemented actually as methods of a special class in each X# dll. The compiler just hides all those implementation details and allows you to simply call ALen(), while under the hood what you are really calling is XSharp.RT.Functions.AAdd(), where "XSharp.RT.Functions" is the name of that special class, and "ALen" is a method of that class.

    If you had redefined ALen() in your own code:

    FUNCTION ALen(a AS ARRAY) AS DWORD
    // my own version of ALen() for any reason
    RETURN 17 // just because :)

    then any of your calls to ALen() in your code would resolve to that version of the function (so you would "override" the standard implementation of the function). In order to call the original version in the X# dll, you would need to call it with the full name mentioned in the beginning.

    I hope this clears up the confusion.
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Last edit: by Chris.

    Overriding a Function in a class... 11 Apr 2019 19:40 #8379

    • FoxProMatt
    • FoxProMatt's Avatar
    • Topic Author


  • Posts: 430
  • Okay, I think I'm starting to get what you are saying, as it related to just raw Functions. So I have learned something with this.

    However, back to my original concern, I just wanted know if I have a Class defined of my own type, and then I subclass it, and add an override (in the C# sense of overriding a Method), when I want to called the original base method, I can do it with Super:X(). Right?

    But if I were overriding one of RT Functions, you cannot call Super(), you must make a hard call to the function in the XSharp.RT namespace.

    Is all this correct?

    Please Log in or Create an account to join the conversation.

    Overriding a Function in a class... 11 Apr 2019 19:54 #8380

    • lumberjack
    • lumberjack's Avatar


  • Posts: 714
  • FoxProMatt_MattSlay wrote: Is all this correct?

    Yes sir, I think you have become a SUPER master
    ______________________
    Johan Nel
    George, South Africa

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1