Start up function in library
Posted
#1
(In Topic #134)
Regular

At the moment I have to remember to call a startup procedure from my project each time.
GB 3.9.2
Posted
Regular

Posted
Regular

I have a library which that performs a number of mysql routines.
A connection to the database is required before the routines will run.
Have tried:-
But nothing happens.
In the Gambas wiki reference is made to automatically invoking a startup routine but this is all it says:-
"There is a better way. It will happen automatically and independently of your main project execution logic.[More to come…]"
So is there a way to avoid having always to call a startup procedure from the project us a library?
Posted
Regular

Try to read up on the Gambas object model here to get a better understanding of this: /doc/object-model - Gambas Documentation
Taking a look in the Gambas farm on how people are doing this can also be enlightening
Posted
Expert

Use a class to instantiate your SQLite database
when the Module starts assign this class to a "$Con" variable
You can then use the _new() in the class to do what you need.
so you get something like this Mod_Global.DB.$Con.
The downside is that your library will depend on this convention always being used.
Cheers - Quin.
I code therefore I am
I code therefore I am
Posted
Administrator

I was checking some old post when I ran into this one.
Maybe a bit of a very late reply, but this might do the trick.
As your library needs a start up class anyway, you might as well use that class to your advantage.
In that class define a:
to make the library do stuff you want it to do at start up of the library
More info on init() see: /lang/special/init - Gambas Documentation
Haven't tested this myself (but I will in 2 days at work in my own libraries)
gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories
… there is always a Catch if things go wrong!
1 guest and 0 members have just viewed this.

