Inheritance problem

This forum is meant for questions and discussions about the X# language and tools
FdeRaadt
Posts: 31
Joined: Wed Sep 01, 2021 12:49 pm

Inheritance problem

Post 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
User avatar
Chris
Posts: 4573
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Inheritance problem

Post by Chris »

Hi Frank,

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

XSharp Development Team test
chris(at)xsharp.eu
FdeRaadt
Posts: 31
Joined: Wed Sep 01, 2021 12:49 pm

Inheritance problem

Post 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
Attachments
VOSplitWindow.png
VOSplitWindow.png (4.76 KiB) Viewed 373 times
VOLayout.png
VOLayout.png (12.72 KiB) Viewed 373 times
X#Layout.png
X#Layout.png (14.25 KiB) Viewed 373 times
errorInheritance.png
errorInheritance.png (11.8 KiB) Viewed 373 times
User avatar
Chris
Posts: 4573
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Inheritance problem

Post 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?

.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
wriedmann
Posts: 3649
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Inheritance problem

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Inheritance problem

Post 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
User avatar
robert
Posts: 4241
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Inheritance problem

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
wriedmann
Posts: 3649
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Inheritance problem

Post 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
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

Inheritance problem

Post 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
User avatar
lumberjack
Posts: 723
Joined: Fri Sep 25, 2015 3:11 pm
Location: South Africa

Inheritance problem

Post 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?
______________________
Johan Nel
Boshof, South Africa
Post Reply