xsharp.eu • Inheritance problem
Page 1 of 2

Inheritance problem

Posted: Mon Nov 29, 2021 9:03 am
by FdeRaadt
Hello Everyone,

I seem to have a problem with Inheritance in X# which does not occur in VO.

In X# the chain of inheritance stops at the first base class.
In VO the chain of inheritance stops at the last possible class.

example:

If i want to acces a method which uses the class Window

e.g
method SavePosition(something, something) class Window

In VO i can use any class that inherits Window.
for example: ChildAppWindow, DataWindow, AppWindow.
all of these classes are child classes of the base class Window

I've ran into the common problem in X# that if I use an a child class like DataWindow.
It only gives me acces to Datawindow and its methods but not the methods of Window.

I understand that these base classes are loaded with the VOGUICLASSES.dll but is there a way to gain access to the highest possible level instead of the specifed child class?

Thanks in advance

Frank

Inheritance problem

Posted: Mon Nov 29, 2021 9:39 am
by Chris
Hi Frank,

Not sure I understood what you mean, can you please show a small code sample to demonstrate this?

Inheritance problem

Posted: Mon Nov 29, 2021 10:10 am
by FdeRaadt
Error XS1061 'NBitWindow' does not contain a definition for 'Layout' and no accessible extension method 'Layout' accepting a first argument of type 'NBitWindow' could be found (are you missing a using directive or an assembly reference?)

NBitWindow inherits SplitWindow
Splitwindow has access to the layout method,

I've included screenshots for clarification

It looks to me that in X# Multi level inheritance is not a thing or is not working on my machine.

Frank

Inheritance problem

Posted: Mon Nov 29, 2021 10:20 am
by Chris
Hi Frank,

I just tried this and compiles without errors:

Code: Select all

CLASS MySplitWindow INHERIT SplitWindow
	METHOD DoTest()
		SELF:Layout := Dimension{1,2}
	RETURN
END CLASS
Maybe it's a problem with missing differences in your project, or some other thing that I can't think of, would it be possible to zip and send your project so we can have a look? Or maybe can you try reproducing the error in a small test mdi app?

.

Inheritance problem

Posted: Mon Nov 29, 2021 10:29 am
by wriedmann
Hi Frank,
PMFJI: the error message says:

Code: Select all

Error XS1061 'NBitWindow' does not contain a definition for 'Layout' and no accessible extension method 'Layout' accepting a first argument of type 'NBitWindow' could be found (are you missing a using directive or an assembly reference?)
Do you are passing a "self" parameter to the Layout() method instead of a numeric value?
Wolfgang

Inheritance problem

Posted: Mon Nov 29, 2021 11:19 am
by ic2
Hello,

The problem is this.

We have a method e.g.

Method DoSomething Class Window

We can reach this method easily from every subclassed window just by calling self:DoSomething.

That is not possible in X#.

We could make a subclass from Class Window and make the methods from this subclass.

But all the different windows (like Datawindow, Splitwindow) etc eventually inherit from Window (say MyWindow) but not via the same inheritance path.

Only if we add everywhere:

Class MyDataWindow inherit MyWindow
method MyPreviousMethodFromClassWindow class MyWindow
then every (previous) window method can be called as follows:

self:MyPreviousMethodFromClassWindow

But... that won't work because MyDatawindow (and all subclassed windows) do not inherit directly from Window. Datawindow inherits from ChildAppWindow, ChildAppWindow from AppWindow and finally AppWindow from Window.

So in short: how do we call methods in X# which in VO are from class Window?

Dick

Inheritance problem

Posted: Mon Nov 29, 2021 11:55 am
by robert
Dick,

You can add an extension method to the Window class and then it will be available to subclasses as well.
The only disadvantage is that you can't access hidden or protected methods / fields/ properties in an extension method (at least not without "dirty tricks").

Robert

Inheritance problem

Posted: Mon Nov 29, 2021 1:19 pm
by wriedmann
Hi Dick,
I'm really sorry, but what you are asking is working (and if that would not work, all the object oriented programming would not work.
Please see this compiling and working code:

Code: Select all

class Upper

constructor()

	return

method MyUpper() as string

	return ""

assign MyVal( cVal as string ) as void

	return

end class

class Lower inherit Upper

constructor()

	self:MyUpper()
	self:MyVal		:= ""

	return

end class
That does exactly what you need.
I suspect that there is something other wrong with this code.
But as Robert wrote: you cannot add methods to the class Window as in VO if you don't recompile the VO SDK or if you use extension methods.
Wolfgang

Inheritance problem

Posted: Mon Nov 29, 2021 2:10 pm
by ic2
Hello Wolfgang,

Frank is trying the Extension methods, I now remember having had some info from Chris about this 1,5 year ago.

What you write does not work with Windows methods. In theory I could do this:

In VO:

Code: Select all

METHOD DoSomething Class Window
Self:StatusMessage("Show something")  // This is a default method of class window
return nil

Code: Select all

method SomeMethod class MyDataWindow
self:DoSomething()
This could be rewritten in VO while still working in X# as follows when I add:

Code: Select all

class MyWindow inherit WIndow

Code: Select all

method SomeMethod class MyDataWindow
local o as MyWindow
o:=MyWindow{}
o:DoSomething()
But this will run the init (Constructor) of the windows class/subclass and that may be something which is taking a lot of time for running only a simple method.

I checked my own code and I do not have any methods from class window anymore. I use the VO equivalent of Extension methods.

But the project Frank is working on still has lots of these methods.

Dick

Inheritance problem

Posted: Mon Nov 29, 2021 3:43 pm
by lumberjack
HI Frank,
FdeRaadt wrote:Hello Everyone,

I seem to have a problem with Inheritance in X# which does not occur in VO.

In X# the chain of inheritance stops at the first base class.
In VO the chain of inheritance stops at the last possible class.

example:

If i want to acces a method which uses the class Window

e.g
method SavePosition(something, something) class Window

In VO i can use any class that inherits Window.
for example: ChildAppWindow, DataWindow, AppWindow.
all of these classes are child classes of the base class Window

I've ran into the common problem in X# that if I use an a child class like DataWindow.
It only gives me acces to Datawindow and its methods but not the methods of Window.

I understand that these base classes are loaded with the VOGUICLASSES.dll but is there a way to gain access to the highest possible level instead of the specifed child class?

Thanks in advance

Frank
Not sure if I understand you correctly but don't you achieve it with o:SUPER:SUPER:SUPER:WhatEverMethod?