DLL init & close problem

Posted on 2006-03-21
Last Modified: 2010-04-05
Hi there

I have a problem with a dll I am writing.
The DLL produces a report from a BDE databse using Crystal Reports.
When used by a single exe it works fine.
However, when I open 2 exes, & print a report from both (using dll calls), I encounter a problem.

All appears to run OK, but when I close the second exe, it does not exit.  Although it dissappears from the screen, it is still visible in the processes list on the task manager.
Until I terminate this unclosed process, I cannot run any BDE apps.  They all appear in the process list too, but never make it to the screen.

I think it has something to do with the exes closing down - maybe the first exe to close clears the dll memory so the second one can't close it & locks up.

Here is a brief description of my dll:

There are 2 data modules: Reportdata & CommonData

The dll project file has them in it's uses clause, ie

uses ... ReportData, CommonData...

The ReportData module also "uses CommonData" in it's implementation section uses clause

There are 4 exported functions, all of which are coded in ReportData:
InitReport, CalcReport, ShowReport, CloseReport.

InitReport does this:
if ReportDataModuleVariable = nil then ReportDataModuleVariable := TReportDataModule.create(nil)
if CommonDataModuleVariable = nil then CommonDataModuleVariable := TCommonDataModule.create(nil)

The CloseReport procedure is similar
if ReportDataModuleVariable <> nil then
if CommonDataModuleVariable<> nil then

The exes that use the dll call InitReport first, & Close Report when they exit

I am hoping that there is somethings basic I am getting wrong with my dll - it is the first one I have done so I have been guessing everything
Question by:dcl
    LVL 21

    Accepted Solution

    if ReportDataModuleVariable <> nil then begin; ReportDataModuleVariable:=nil; end;
    if Assigned(ReportDataModuleVariable) then ReportDataModuleVariable := TReportDataModule.create(nil)

    if You call .Free it doesnt mean that variable will be nil

    LVL 1

    Author Comment

    Thanks ziolko

    While implementing your suggestion I also found I was not actually calling the CloseReport method correctly, so that helped too.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
    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…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    This video discusses moving either the default database or any database to a new volume.

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now