Sendclass substitute

This forum is meant for questions and discussions about the X# language and tools
User avatar
Kees Bouw
Posts: 133
Joined: Wed Nov 06, 2019 11:35 am
Location: Netherlands

Re: Sendclass substitute

Post by Kees Bouw »

Chris wrote: Tue Feb 04, 2025 9:54 am Hi Kees,

You can do something similar to what you already did:

- Create a METHOD OKButton_class_B() CLASS B (or with a different name) and put there all the code that is currently in included in OKButton() of this class B
- In OKButton() of this class put only a simple call to this new OKButton_class_B() method.
- When you need to call the OKButton() method of that level in a subclass (from F as you mentioned), simply call SELF:OKButton_class_B(), instead of using SendClass().

That should do the trick.
Hi Chris,

Thank you very much, that works fine indeed. I still find it strange that in my previous attempt, while executing a method of class B and doing a SELF:OKButton(), the OKButton() of class F is executed instead of the one in class B. When code is executed in a method of a certain class, then should not SELF refer to that same class?

Kees.
User avatar
Chris
Posts: 5079
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Sendclass substitute

Post by Chris »

Hi Kees,
Kees Bouw wrote: Wed Feb 05, 2025 8:48 am Thank you very much, that works fine indeed. I still find it strange that in my previous attempt, while executing a method of class B and doing a SELF:OKButton(), the OKButton() of class F is executed instead of the one in class B. When code is executed in a method of a certain class, then should not SELF refer to that same class?
Yes, that's how it always works in VO, all methods are what we call "virtual", meaning that they can be overridden by child classes. So when you define a method with the same name (and signature (parameters and return value), which is always enforced in VO) in a subclass, all calls to this method are resolved to calling the method in the last class in the inheritance chain. That's how callbacks like EditFocusChange() work, those are defined inside the VOGUI classes library and called by other code inside it, but if you redefine (override) them in your own window (sub)class, then your method gets called, instead of the one in the VOGUI classes.

In .Net, we have the option to let methods be non-virtual and mark only those that we want as VIRTUAL, if they are intended to be overridden by a subclass (callback methods for example). This way it will work as you expected it, calling a method from class_B will call the method defined in this class (or in the parent class_A, if class_B does not define it) and not the same named method that may be defined in the child class_C. That's actually the default behavior in .Net (and X#), but you have probably enabled (or VOXporter did it) the "All instance methods virtual" option in your project settings (Dialect page), which automatically marks all methods you define yourself as VIRTUAL, for compatibility with VO.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply