Why do we have to call Super.New for windows instances

About Monkey 2 Forums Monkey 2 Programming Help Why do we have to call Super.New for windows instances

This topic contains 2 replies, has 2 voices, and was last updated by  abakobo 2 years, 10 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1885

    abakobo
    Participant

    the following code won’t compile (error no constructor)
    <pre class=”lang:monkey decode:true ” title=”no constructor is called…”>
    #Import “<std>”
    #Import “<mojo>”

    Using std..
    Using mojo..

    Class MyWindow Extends Window
    Method OnRender( canvas:Canvas ) Override
    canvas.DrawText(“hellow”,110,30)
    End Method
    End Class

    Function Main()
    New AppInstance
    New MyWindow(“HELLOW”,1000,600,WindowFlags.Resizable)
    App.Run()
    End Function

     

     

    So we have to call the constructor by ourselves adding the New method
    <pre class=”lang:monkey decode:true “>

    #Import “<std>”
    #Import “<mojo>”

    Using std..
    Using mojo..

    Class MyWindow Extends Window
    Method New(title:String,w:Int,h:Int,flag:WindowFlags)
    Super.New(title,w,h,flag)
    End Method
    Method OnRender( canvas:Canvas ) Override
    canvas.DrawText(“hellow”,110,30)
    End Method
    End Class

    Function Main()
    New AppInstance
    New MyWindow(“HELLOW”,1000,600,WindowFlags.Resizable)
    App.Run()
    End Function

    why the super constructor is not called automatically if no method is declared? it complicates things (not usefully?).

    Is the constructor the only thing that is not inherited automatically?

    PS: sorry I don’t get how to embed code with the crayon thing…

    #1932

    Jesse
    Participant

    I haven’t looked into it but I assume hats how you pass those values to the window class.

    and for your information you don’t need to use “Super” for the New method  unless you have a “New” method  in the extended class. you do on the OnWindowEven so as not to confuse the one in the extended class from the window class.

    #1950

    abakobo
    Participant

    I pass the values this way:

    New MyWindow(“HELLOW”,1000,600,WindowFlags.Resizable)

    Wich corresponds to the docs: String, Int, Int, WindowFlags

    Or should I write the flag another way? It works written this way in the second example. (I’m not used to enums)

    I haven’t found any example not using super.new for creating a non default window.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.