We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

DLL init & close problem

dcl
dcl asked
on
Medium Priority
203 Views
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 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
Comment
Watch Question

software developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
try
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

ziolko.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
dcl

Author

Commented:
Thanks ziolko

While implementing your suggestion I also found I was not actually calling the CloseReport method correctly, so that helped too.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.