[Gambas-user] Component as dynamic plugin's

olivier coquet ocoquet at 3d-phenomen.fr
Fri Feb 12 10:13:34 CET 2021


Hello everyone,

For some time now I've been looking for a way to create plugins that can 
add functions to a main program in a dynamic way.
I finally succeeded (with the help of Tobias, many thanks to him).
Here's how I'm doing it:

I start by creating a component whose name always starts with "*PLG_*".
This component creates a class with the same name as the component, for 
example if the component is called "*gb.PLG_TEST*" the class will be 
"*PLG_TEST*".
This class includes at least one method "*plg_main*", it is this method 
that will add functions. It takes as argument the reference to the main 
window (Me).

I install the component.

In my main program, at startup, I do a search for available components, 
I make a list of components that start with "*PLG_*".
 From this list, I load these components with (in a loop):

/   Dim PlugComponent As Component //
//   PlugComponent = Component.Load(ComponentName) /

then (thank you Tobias):

/Dim hclass As Class = Classes [ComponentClassName] //
////ComponentClassName is the component name minus the prefix.//
//   Dim PlugClass As Object = hclass.New()/

lastly, I launch the initialization method of the component with:

/PlugClass.Plg_main(Me)/

That's it, it's done.

My first test is a plugin that adds buttons and their management to the 
main window of my program.

This system has the advantage of being able to add functions to an 
already written program without having to modify it, or to update some 
features without a complete rewrite.


I hope it will be useful to someone.

Friendship
Olivier Coquet

Translated with www.DeepL.com/Translator (free version)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210212/03c6ea58/attachment.htm>


More information about the User mailing list