[Gambas-user] How to execute a standard routine every time a function in a component is called

Benoit Minisini gambas at ...1...
Wed Dec 10 15:42:10 CET 2008


On mercredi 10 décembre 2008, gambas at ...1938... wrote:
> Am Mittwoch, 10. Dezember 2008 15:04:08 schrieb Benoit Minisini:
> > On mercredi 10 décembre 2008, gambas at ...1938... wrote:
> > > Hi Gurus!
> > >
> > > Sorry for this noop-question:
> > > In the module area of my component I read a settings file with some
> > > connection parameters.
> > > As long as I run the component as a normal Gambas-programm this works
> > > perfectly. But when I turn it into a component and call one of it's
> > > exported functions, the function is called directly, without executing
> > > the code in the module area and my connection parameters are never
> > > read. Surely there is a another way than putting the reading of the
> > > settings file into every single function...but which way?
> > >
> > > TIA and grretz
> > > Stevie
> >
> > A class can have an "_init" special static public method that is called
> > the first time a class is used. You can use that.
> >
> > A component written in Gambas has no global initialization function.
>
> Thanks for the hint, but I can't get it going. I put this into the module
> area:
>
> Static Public Sub _init()
> ' Read config file
>   Dim hCFG As New Settings(User.Home &/ "etc/some.cfg")
> End
>
> When compiling I get:
> Unxepected Static
>

A module is just a class where everything is static, so the STATIC keyword is 
not needed.

> Next question: How do I have to define hCFG? Dim, Private???
> ...I think, I need a good newby-book about Gambas and OO! ...but where to
> get?? :-)

It depends where you need to use it.

Regards,

-- 
Benoit Minisini




More information about the User mailing list