DLL init & close problem

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 ReportDataModuleVariable.free
if CommonDataModuleVariable<> nil then CommonDataModuleVariable.free

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dclAuthor Commented:
Thanks ziolko

While implementing your suggestion I also found I was not actually calling the CloseReport method correctly, so that helped too.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.