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

TOPIC:

Inheritance problem 29 Nov 2021 10:03 #20576

  • FdeRaadt


  • Posts: 9
  • 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

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 10:39 #20577

    • Chris
    • Chris's Avatar


  • Posts: 2955
  • Hi Frank,

    Not sure I understood what you mean, can you please show a small code sample to demonstrate this?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 11:10 #20578

    • FdeRaadt


  • Posts: 9
  • 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

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 11:20 #20579

    • Chris
    • Chris's Avatar


  • Posts: 2955
  • Hi Frank,

    I just tried this and compiles without errors:
    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?

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 11:29 #20580

    • wriedmann
    • wriedmann's Avatar


  • Posts: 2878
  • Hi Frank,
    PMFJI: the error message says:
    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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 12:19 #20581

    • ic2


  • Posts: 1220
  • 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

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2.

    Inheritance problem 29 Nov 2021 12:55 #20583

    • robert
    • robert's Avatar


  • Posts: 2593
  • 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

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 14:19 #20590

    • wriedmann
    • wriedmann's Avatar


  • Posts: 2878
  • 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:
    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

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Last edit: by wriedmann.

    Inheritance problem 29 Nov 2021 15:10 #20597

    • ic2


  • Posts: 1220
  • 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:
    METHOD DoSomething Class Window
    Self:StatusMessage("Show something")  // This is a default method of class window
    return nil
    method SomeMethod class MyDataWindow
    self:DoSomething()

    This could be rewritten in VO while still working in X# as follows when I add:
    class MyWindow inherit WIndow
    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

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 16:43 #20609

    • lumberjack
    • lumberjack's Avatar


  • Posts: 710
  • 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
    George, South Africa

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 16:52 #20610

    • robert
    • robert's Avatar


  • Posts: 2593
  • Dick,

    Look at www.xsharp.eu/help/example-2-the-vopad-example.html and how we added the extension method RTFChangeFont().

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 20:56 #20615

    • FFF


  • Posts: 1263
  • I thought he wants to access no "new" method, but simply an existing method of the base class??
    And Dick, I can't imagine using the methods of an object which is not initialised.
    Regards
    Karl (X# 2.7; Xide 1.27; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    Inheritance problem 29 Nov 2021 23:08 #20619

    • ic2


  • Posts: 1220
  • Hello Robert, Karl, Johan,

    We instantiate for example a ContactWindow which inherit from MyDatawindow, which inherits from Datawindow and ends with Class Window.
    But trying to run a Windows subclass (former Class Windows) method would re-instantiate the Windows (sub)class.

    I found out that in my own code I already use the VO version of Extensions:
    CLASS IC2WindowExtender
    EXPORT oWin AS Window
    
    METHOD INIT(oWindow) CLASS IC2WindowExtender
    SELF:oWin := oWindow
    RETURN SELF

    A sample method for one of the windows subclasses will be:
    METHOD SetColours(nFgr,nFgg,nFgb,nBgr,nBgg,nBgb) CLASS IC2DialogWindow
    //#s Calls super method 
    LOCAL oIC2Win AS ic2WindowExtender
    oIC2Win:=IC2WindowExtender{SELF}
    oIC2Win:SetColours(SELF,nFgr,nFgg,nFgb,nBgr,nBgg,nBgb)
    RETURN TRUE

    I think this will work in X# too and then it minimizes conversion time, if we change this in VO. The extensions as Robert pointed to in sample code are a good direct X# solution, we cold also use this. And Johan's super:super etc should work too, but I don't like these construction as it doesn't clearly show you where your method runs from. You have to count (supers) and could easily miscount I am afraid.

    Thanks for all suggestion. When Frank is ready and it works he or we will summarize the results here.

    Dick

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2.

    Inheritance problem 30 Nov 2021 08:26 #20624

    • robert
    • robert's Avatar


  • Posts: 2593
  • Dick,
    Your solution uses (IIRC) the Decorator Pattern.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    Inheritance problem 30 Nov 2021 11:27 #20630

    • wriedmann
    • wriedmann's Avatar


  • Posts: 2878
  • Hi Dick,
    and what about that:
    static METHOD SetColours( self oWin as Window, nFgr as dword ,nFgg as dword,nFgb as dword,nBgr as dword,nBgg as dword,nBgb as dword) as void // CLASS IC2WindowExtender
    // your code to set window color
    RETURN TRUE
    and on your window call simply
    self:SetColours( 1, 1, 1, 1, 1, 1, 1 )
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Inheritance problem 30 Nov 2021 12:18 #20632

    • ic2


  • Posts: 1220
  • Hello Robert,

    robert wrote: Your solution uses (IIRC) the Decorator Pattern.


    I didn't know that term, but found some explanation (e.g. sourcemaking.com/design_patterns/decorator )

    I have applied this in 2009 preparing for Vulcan, a bit like a VO implementation of of multiple inheritance.

    Dick

    Please Log in or Create an account to join the conversation.

    Inheritance problem 30 Nov 2021 12:23 #20633

    • ic2


  • Posts: 1220
  • Hello Wolfgang,

    wriedmann wrote: and what about that:
    static METHOD SetColours( self oWin as Window, nFgr as dword ,nFgg as dword,nFgb as dword,nBgr as dword,nBgg as dword,nBgb as dword) as void


    That is what Robert suggested in this thread. But that's X# only.

    What we try to do is adapt VO as much as possible so the actual VO->X# move would take minimal time. Everything we can't prepare in VO, e.g. our Office OLE classes will use Office.Interop .Net classes, is documented or will be code set aside to be inserted once we convert the project Frank is working on.

    Should we convert directly then we will have a long period, at least weeks or more, in which the daily maintenance can not be done or must be done twice, in the VO program and applied again in the program to be converted.

    Dick

    Please Log in or Create an account to join the conversation.

    Last edit: by ic2.

    Inheritance problem 30 Nov 2021 13:34 #20638

    • wriedmann
    • wriedmann's Avatar


  • Posts: 2878
  • Hi Dick,
    personally I prefer the solution with the extension method as suggested by Robert because it is more compatible with the VO side of code.
    In my VO code I have these extensions to the original VO classes in a separate module.
    In the X# version this module does not exists, but there is another module with all the extension methods.
    And in the application and library code there is no difference as I can write the same code, calling the methods normally.
    Maybe I have to explain better:
    VO side
    method xyz() class Window
    .....
    return nil
    X# side
    class VOExtensions
    static method xyz( self as Window ) as void
    ....
    return
    end class
    and in both VO and X# code I can simply write:
    oWindow:xyz()
    or inside the class
    self:xyz()
    I hope I was able to explain that.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    Inheritance problem 30 Nov 2021 17:08 #20640

    • ic2


  • Posts: 1220
  • Hello Wolfgang,

    Frank will read this all Wednesday and we should decide then what to choose.

    To keep the Windows methods in VO isn't really a problem if the X# conversion is close. My change means there's no need for a further conversion once the actual conversion takes place to X# (everything Frank is doing now is preparing VO changes, notes what to do and having X# specific libraries ready so in a while he should be able to convert the live VO solution definitely to X# within a day or a few days, instead of weeks.

    Your solution means that he has to encapsulate every class window method with the static class code but it won't be too much work.

    Thanks everyone for contributing.

    Dick

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1