Newsgroups : Borland : borland.public.delphi.rtl.win32 : 2005 Aug : getting "file in use" error

www.cryer.info
Managed Newsgroup Archive

getting "file in use" error

Subject:getting "file in use" error
Posted by:nospam@usa.net
Date:Sat, 27 Aug 2005 21:41:49

This really has me stumped.  I have an app that does email, been
working fine for several years.  It uses the IMS components.  They are
no longer being developed and the author does not really support them
any more, although still for sale, and very solid IMO.

An email message MailComponent has a SaveToFile method for each
incoming email, and a LoadFromFile method to get the info into the
component, then the info can be displayed.

When the user clicks on a control in the app, the relevant code is:

var
  MailFile : string;
begin
  MailFile : {the full path and name of the file in which the email was
stored}
  MailComponent.LoadFromFile(MailFile);

When the email is small, it works fine as it always did.  But if the
email has attachments, so is large, I get the error "The process cannot
access the file because it is being used by another process."

A couple emails with small attachments have stored sizes of 248k and
379k, they usually - but not always - work fine, but sometimes get the
error.  A couple more are 1060k and 1180k, they always get the error.

I looked at the component's source and the LoadFromFile method actually
uses a FileStream, if that is relevant.

soemthing strange:  if I put, for testing, right before the
LoadFromFile line above, a Showmessage('Got this far') then run it, it
always works, even on the large email files.  So I tried other things
to add a "delay", like Sleep and Application.ProcessMessages, but that
did not fix it.

There's something I changed in the app "about" the time I started
getting this error, not sure if exactly the same time, don't think it
could be related but I mention it anyway.  The old way to start the
procedure was when the user clicked on a DBListview, a third-party
data-aware listview.  I changed it to the standard DBGrid.

Any ideas?

Replies:

www.cryer.info
Managed Newsgroup Archive