Does anyone know if this can be done?
At the moment I have to remember to call a startup procedure from my project each time.
GB 3.9.2
Start up function in library
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Start up function in library
What exactly do you mean by a "start up function"? A function that is run when the library is accessed? In that case, if it is an object, you can utilize the constructor, _new().
-
- Posts: 195
- Joined: Tuesday 26th September 2017 3:17pm
- Location: NW England
Re: Start up function in library
Thanks for the reply.
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:-
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?
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:-
Public Sub _new()
Initialise()
End
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?
Re: Start up function in library
You cannot use _new if the library is static. A module is a static class, i.e. it cannot be created, only accessed directly. If you put the library code in a class file, you can create objects out of it, and this is where _new comes in. As the new object is created, you can have it initialise the connection with _new.
Try to read up on the Gambas object model here to get a better understanding of this: http://gambaswiki.org/wiki/doc/object-model
Taking a look in the Gambas farm on how people are doing this can also be enlightening
Try to read up on the Gambas object model here to get a better understanding of this: http://gambaswiki.org/wiki/doc/object-model
Taking a look in the Gambas farm on how people are doing this can also be enlightening
- Quincunxian
- Posts: 173
- Joined: Sunday 25th June 2017 12:14am
- Location: Western Australia
Re: Start up function in library
You can still use a Module to do this I think
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.
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
Re: Start up function in library
Hi,
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:
More info on init() see: http://gambaswiki.org/wiki/lang/special/init
Haven't tested this myself (but I will in 2 days at work in my own libraries)
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:
Public Sub _Init()
'your code here
End
to make the library do stuff you want it to do at start up of the libraryMore info on init() see: http://gambaswiki.org/wiki/lang/special/init
Haven't tested this myself (but I will in 2 days at work in my own libraries)
gbWilly
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!
- Dutch translation for Gambas3
- Gambas wiki content contributer
... there is always a Catch if things go wrong!