Inheritance problem
Inheritance problem
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
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
Hi Frank,
Not sure I understood what you mean, can you please show a small code sample to demonstrate this?
Not sure I understood what you mean, can you please show a small code sample to demonstrate this?
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Inheritance problem
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
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 (4.76 KiB) Viewed 600 times
-
- VOLayout.png (12.72 KiB) Viewed 600 times
-
- X#Layout.png (14.25 KiB) Viewed 600 times
-
- errorInheritance.png (11.8 KiB) Viewed 600 times
Inheritance problem
Hi Frank,
I just tried this and compiles without errors:
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?
.
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
.
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Inheritance problem
Hi Frank,
PMFJI: the error message says:
Do you are passing a "self" parameter to the Layout() method instead of a numeric value?
Wolfgang
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?)
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Inheritance problem
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
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
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
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
The Netherlands
robert@xsharp.eu
Inheritance problem
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:
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
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
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
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Inheritance problem
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:
This could be rewritten in VO while still working in X# as follows when I add:
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
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()
Code: Select all
class MyWindow inherit WIndow
Code: Select all
method SomeMethod class MyDataWindow
local o as MyWindow
o:=MyWindow{}
o:DoSomething()
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
- lumberjack
- Posts: 726
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
Inheritance problem
HI Frank,
Not sure if I understand you correctly but don't you achieve it with o:SUPER:SUPER:SUPER:WhatEverMethod?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
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa