0

I read many questions on StackOverlow about plugins in Delphi (like this one).

Anyway I still have a doubt and I would like to discuss my real case scenario.

i develop a huge application, just to give an idea it is a "fat client" client/server application, with 80MB of exe (big size is mainly due to many 3rd party components I use).

I have the requirement to modify this application too much, so i ended up with the idea of writing plugins, because once a "plugin foundation" is made i think i can add new features more quickly.

My initial idea was to write exes as plugins (i can pass from the main application a command line parameter to the plugin exe where i pass the connection string to the db - encrypted maybe).

But i realize this limits me too much. (and that an exe is not a "real plugin")

Let me try to express myself by a realworld example.

My applciation has many forms, most of them with a tabcontrol.

Let's take the Customers (think to CRM software) form.

This form has a main tab with main data (company name, address, main phone, main email address, ...), then there is a Contacts tab (list of contacts with their personal data), plus many other tabs specific to my application.

Let's say that I'd like to add a new tab from a plugin.

I make a silly example.

Plugin is ChristmasGIfts.dll (to manage comapny gifts i do to customers for Christmas)

This plugin should add a new tab with Caption "Xmas Gifts" in the Customers form.

The content of the tab will be a "frame/form" that allows the user to define which gifts should be sent to the customer for next XMas + see the history of last years.

So this "new tab" will have its own logic (a datamodule) and its own controls (a frame/form).

Moreover as i click on the "Save" button my main applcation must validate also the plugin data (for example "you must insert at least a XMas gift").

It is not clear to me how to lay down this architecture.

Somehow my question is:

1) how to extract a frame/form from a dll to add it at runtime to my form?

2) how to delegate the dll to do data validation and return a message

I hope you can help.

Community
  • 1
  • 1
UnDiUdin
  • 14,924
  • 39
  • 151
  • 249

1 Answers1

1

First of all, stop thinking on plugins as DLLs. In Delphi, they should be packages. Delphi packages are DLLs, but they carry type information so they can easily integrate to your main application. Have you seen some wizards in Delphi? They are all packages that implement forms, frames and maybe even DataMdules, loaded by the Delphi IDE, precisely as you want in your application.

Usually what you do is to declare a plugin class in some infrastructure package (TPlugIn, for instance) or eventually an interface (IPlugIn) and use it in your main application and in your plugint plackages.

Each plugint package should declare an entry point function (for instance, a function named StartPlugIn) that will return you the plugin instance. This class or interface will give you some methods to interact with, allowing you to command the instantiation of a frame or validanting the data or what ever your like. For instance, this instance can inform your application to create a new main menu item to access it.

Your main application will have to know all the packages it should load. For instance, you may stablish a folder where all the pluging packages must be stored. When the application starts, it will load all the packages existing in this folder and load all the plugins. Then, when the time comes, the plugins will start working.

This is, in my opinion, a design that will give you all you want to get to.

AlexSC
  • 1,823
  • 3
  • 28
  • 54
  • Thanks a lot for the answer. I will explore, it seems the way to go. Do you have a useful sample to start from? – UnDiUdin Sep 15 '14 at 12:36
  • 1
    @user193655: sorry, but I don´t have a real sample ready. I will work on a basic model for you and edit my answer to present it, ok? it will take me a two or three days, so I have to ask you to wait a little. – AlexSC Sep 15 '14 at 12:55
  • that would be great, but please don't work for me. – UnDiUdin Sep 15 '14 at 14:47
  • 2
    Packages compel plugin authors to use the exact same version of Delphi as you do. That's a very heavy constraint. – David Heffernan Sep 15 '14 at 15:35
  • @DavidHeffernan I know about this, but i am stuck in Delphi XE2 and this is an acceptable constraint for me. – UnDiUdin Sep 15 '14 at 15:55
  • 1
    If you are writing all the code then I can't imagine that introducing packages will make your life simpler. – David Heffernan Sep 15 '14 at 16:10
  • @DavidHeffernan somehwo you are right, but since my appliation has a limiting DB schema i think to give every plugin some "DB tables" so it will be easy to develop custom features and easy to "install the plugin" to more than 2 customer. So plugin is not only "a button in the UI", but also a "dedicated DB tables + stored procedures" + a web (intraweb) application to serve an additional web UI – UnDiUdin Sep 16 '14 at 19:49