Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


DataModule inside a DLL?

Posted on 2003-03-28
Medium Priority
Last Modified: 2012-06-27
I'm developing a modular system (one main .exe and variuos .DLLs) with Delphi 5. I'd like to know the best way to share a database connection with all modules. People have suggested me to put a DataBase component inside each .DLL, but i don't think this is the best way, because each module is gonna make it's own connection to the DataBase Server (InterBase)... I'm trying to put a DataModule inside a .DLL and make it available for each module (.DLL), but i'm having trouble when transferring data between DataModule and the modules...

Does anyone have messed with something like this? Is it really possible to put a DataModule inside a DLL and make it available for all the program? If so, how can I do it, PLEASE????!!!
Question by:bootsector

Accepted Solution

mocarts earned 300 total points
ID: 8224650
first, you must put in uses ShareMem for exe and dll's projects as first, for proper memory handling with reference counted resoruces as strings, interfaces..
next, export from your *connection* DLL function which returns Database component
function GetDB: TDatabase; stdcall;
  Result := DataModule1.Database1;

load this dll as first and save Handle of library somewhere in global variable.
to other dll's which requires Database pass this library handle and these dll's then can find this procedure pointer and respectively get database component:
  TGetDB = function: TDatabase; stdcall;

function NeedDatabase: TDatabase;
  gdb: TGetDB;
  @gdb := GetProcAddress(hPassedConnectionDLLHandle, 'GetDB');
  if @gdb <> nil then
    Result := GetDB;

that's my idea how..

Expert Comment

ID: 9316564
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question