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

TOPIC: Overriding a Function in a class...

Overriding a Function in a class... 6 months 5 days ago #8347

  Matt Slay's Avatar Topic Author Matt Slay Offline Posts: 217
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... 6 months 5 days ago #8348

  Chris Pyrgas's Avatar Chris Pyrgas Offline Posts: 1402
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... 6 months 5 days ago #8350

  Matt Slay's Avatar Topic Author Matt Slay Offline Posts: 217
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 Matt Slay.

Overriding a Function in a class... 6 months 5 days ago #8351

  Johan Nel's Avatar Johan Nel Offline Posts: 568
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 Johan Nel.

Overriding a Function in a class... 6 months 5 days ago #8352

  Jamal's Avatar Jamal Offline Posts: 147
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... 6 months 4 days ago #8358

  Chris Pyrgas's Avatar Chris Pyrgas Offline Posts: 1402
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... 6 months 4 days ago #8369

  Matt Slay's Avatar Topic Author Matt Slay Offline Posts: 217
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... 6 months 3 days ago #8371

  Johan Nel's Avatar Johan Nel Offline Posts: 568
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... 6 months 3 days ago #8374

  Matt Slay's Avatar Topic Author Matt Slay Offline Posts: 217
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 Matt Slay.

Overriding a Function in a class... 6 months 3 days ago #8377

  Chris Pyrgas's Avatar Chris Pyrgas Offline Posts: 1402
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 Pyrgas.

Overriding a Function in a class... 6 months 3 days ago #8379

  Matt Slay's Avatar Topic Author Matt Slay Offline Posts: 217
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... 6 months 3 days ago #8380

  Johan Nel's Avatar Johan Nel Offline Posts: 568

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