2006/8/15, Michael Van Canneyt <[EMAIL PROTECTED]>:


On Tue, 15 Aug 2006, Bogusław Brandys wrote:

> Alexandre Leclerc wrote:
> > Hi all,
> >
> > an application writes a text file on disk (Windows) and my FPC
> > application opens it to process it. On some systems I open the file
> > faster than the OS has finished writing it. I then get an 'Unexpected
> > end of file'.
> >
> > I would like to know if there is a way I can detect the file is finish
> > written on the disk; else should I simply trap the error and then
> > close/reopen if I get it?
> >
> > Regards.
> >
>
> Other solution is to change this application which writes to text file on
> disk,that way that it should write to temporary file and then change filename
> to destination.Because renaming file is atomic under linux and windows you
> will not worry about file writes.

I think this is the best solution. If both applications are using FPC, then FPC
itself has an internal buffering mechanism. As long as the first application
hasn't really closed the file (and thus flushed the buffer) the second 
application
will only 'see' part of the file, because the OS doesn't know about the FPC 
buffer.

Yes I like this solution; it looks cleaner. The only thing I can
confirm is the 'Unexpected end of file' coming from time to time. Now
I'll go for the renaming trick. It might do the job quite well. I'll
give feedback on this thread the moment I have final results. (A PC of
a client is always doing the thing; this will be the best bench test.)

--
Alexandre Leclerc

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to