[Gambas-user] More on overriding native classes

Bruce bbruen at ...2308...
Mon Jun 25 00:41:44 CEST 2012


On Sun, 2012-06-24 at 22:52 +0200, Benoît Minisini wrote:
> Le 18/06/2012 15:29, Bruce a écrit :
> > On Mon, 2012-06-18 at 22:39 +0930, Bruce wrote:
> >
> >> Try this:
> >> Create a new command line project in the IDE.
> >> Add a new class "Application" with the following contents
> >>
> >>          ' Gambas class file
> >>
> >>          Create Static
> >>          Inherits Application
> >>          Export
> >>
> >>          Static Public Hello As String = "Hello from South Australia"
> >>
> >> Save and reload the project.
> >> In MMain.Main type the following:
> >>
> >>          ?appl[Enter].he
> >>
> >> ( see screenshot appended)
> >> Now that, to me, looks like we have successfully overridden the
> >> Application class, but look what happens when you run it.
> >>
> >
> > Let me rephrase that (sometimes the keyboard is quicker than the mind.)
> >
> > Try this:
> > Create a new command line project in the IDE.
> > Add a new class "Application" with the following contents
> >
> >         ' Gambas class file
> >
> >         Create Static
> >         Inherits Application
> >
> >         Static Public Hello As String = "Hello from South Australia"
> >
> > Save and reload the project.
> > In MMain.Main type the following:
> >
> >         ?appl[Enter].he
> >
> > ( see new! screenshot appended)
> > Now that, to me, looks like we have successfully overridden the
> > Application class, but look what happens when you run it.
> >
> >
> > What you should see is a very correct error message saying that Hello
> > is an unknown method in Application.  That is because it hasn't been exported.
> > But when I go back and export the class, then I get the Multiple Inheritance error.
> >
> > B
> >
> 
> If you export a class with a name that already exists, it automatically 
> implies inheritance with overriding.
> 
> So you have a "multiple inheritance" error by using the "Inherits" keyword.
> 

Wow! That simple.  
Now I can do all those nefarious things I've always wanted :-)

Oh, but wait, one question.

Class initialisation must occur in some specific order (like
constructors and inherited classes), what is it and is there any way to
control it? e.g. by the order of the components and libraries in
the .startup file?

Bruce





More information about the User mailing list