[Gambas-devel] Provide special auto-instance of a class

tobi tobias at ...692...
Thu Apr 5 02:27:19 CEST 2012


On Thu, 05 Apr 2012, Benoît Minisini wrote:
> Le 05/04/2012 01:25, tobi a écrit :
> > Me again,
> >
> > ...
> >
> > I wonder what's wrong with this:
> >
> > GB_DESC CWindowDesc[] = { GB_DECLARE("Window", sizeof(struct
> > nc_window)), ... GB_METHOD("_new", NULL, CWindow_new,
> > "(x)i(y)i(w)i(h)i"), ... };
> >
> > GB_DESC CStdscrDesc[] = { GB_DECLARE("Stdscr", sizeof(struct
> > nc_window)), GB_INHERITS("Window"), GB_AUTO_CREATABLE(),
> >
> > GB_METHOD("_new", NULL, CStdscr_new, NULL),
> >
> > GB_END_DECLARE };
> >
> > It gives a "Not enough arguments" error as soon as I use the Stdscr
> > class, thus on its auto-creation. If i replace GB_AUTO_CREATABLE()
> > with GB_NOT_CREATABLE() the program starts but of course I can't do
> > anything with its properties (wait a minute, not-creatable means that
> > _new() isn't called at all?). I am able to overwrite the inherited
> > function? I'm sure I misunderstand something about inheritance or
> > those IDs. Could anyone point me to the right way?
> >
> > Regards, Tobi
> >
> 
> Because all constructors all called when you use inheritance, and each
> constructor consume arguments. This is explained in the "Gambas object
> model" page on the wiki.
> 
> So I suggest you do differently, as I did in the gb.db component.
> 
> In the gb.db component, you have a Connection class and a DB static
> class that has the same methods and properties as the Connection class,
> except that they are all static.
> 
> So:
> 
> 1) Make your 'Window' class as you did.
> 
> 2) Create a 'StdScr' class with the same methods and properties, except
> that everything is static.
> 
> 3) Both Window and StdScr use the same implementation method.
> 
> 4) In the implementation method, just check the "_object" argument. If
> it is not null, then you are dealing with a Window object. If it is
> null, then you are dealing with the StdScr class.
> 
> Was I clear?
> 

All clear, expect that: I need the members of my struct nc_window. If there is no valid _object, I
have to declare this struct globally (statically) in the source file of my StdScr object?





More information about the Devel mailing list