Using Delphi 2010, I am needing to write a program to support modules, or plug-ins. Although a little contrived, assume I have an app which converts datafiles/text files. It will support 30 input formats and those same 30 formats as outputs. The first release will probably only implement a few of these formats. My challenge is that I want a data driven process flow.
For example, assume I have a PARSE_FILE routine. If my input data file format is 'Format_A', then then when I call PARSE_FILE, it should know to use PARSE_FILE_Format_A, as opposed to the other 29 different versions of the PARSE_FILE routine.
PARSE_FILE is just an an example. I will probably have 60 different common functions, LOAD_FILE, GET_DELIMITER, PARSE_FILE, etc, but each of these functions will be a little different for each of the 30 different formats. What technique can I use so that if I am Loading a file with FORMAT_A, each one of these 60 different common routines uses the proper 'version' of these 60 routines?
Keep in mind that I am starting with just 5 input formats, and will add other formats later, so I need a way of centrally defining this "mapping', so wherever these routines are used throughout my code, the proper version of the routine will be used even though I call the generic version.
A: A plugin is a piece of functionality that can be installed, and once installed dynamically, it can be removed without requiring a rebuild of your application. A module has to be installed as part of the deployment or update process, and once a module is installed, it is very difficult to undo.
A plug-in is a bundle that adds functionality to an application, called the host application, through some well-defined architecture for extensibility. This allows third-party developers to add functionality to an application without having access to the source code.
IFileFormatHandler
,
which contains a PARSE_FILE function, etc.IFileFormatHandler
interface type in one BPL package (ie, Common.bpl) so that all the modules can reference the common interface type. Each plugin module itself is also in its own BPL package. (Multiple file format handlers could exist in the same BPL package, but the baseline example is one per BPL)RegisterPlugin(name: string; instance: IFileFormatHandler)
for example. This registers the plugin name and instance in an internal list that the host application can use to find out what plugins are available and call them.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With