View Full Version : Breaking code into DLLs

25-03-2005, 06:16 AM
Sorry for the basic question, but i'm a VB programmer by day and I'm trying to learn Delphi by night (mostly used C/C++ at home before).

What i'm wondering is if breaking your code down into DLLs in Delphi is a good choice and if so, what's the best way to approach it. I've been reading the developer's guide and it says there are a couple of different kinds, a pure dll that basically uses non-vcl code and then BPLs (i think that's the name) that contains startup code to allow the usage of VCL components in the DLL.

Is there a best way and if so, how do you go about calling the DLLs, via external function definitions (ala declare in VB) or if I go the bpl route, is there a special way I can call those?

I just basically want to modularize my code so if I bugfix a component, I just need to modify the corresponding DLL and then install the new one instead of having it all in one giant monolithic exe. It would also help for expanding backend support as in my case, to support an additional database, I would just drop in the new DLL and the EXE would see the new DLL and make the new database available to select from.

Comments are welcome,


25-03-2005, 06:57 AM
IMHO breaking code into modules is always good. Among other way to split it, dll is quite a radical one :) It force you to have very well defined interfaces between different modules, which is extremely important if you ask me.
On the other side, it gives some extra work: for example for each DLL you have to write a header file in which you import all exported procedure.
Other problems exists for some data types, for example string need some special attentions to be used (as it says when you create a dll in delphi).
Using classes in the DLL interface (for example as a parameter) should work but in this way you will have a DLL that is usable only in delphi and in no other language.
The right way should be creating a plain API interface layer on top of your OO code, with normal flat calls, maybe using pchar instead of strings.
This is obviously some extra work.

Remember that this is only my opinion :P