I'm trying to open a text file for reading in a Delphi 7 app, but am getting I/O error 32 (sharing violation) because another application already has the file open. I've tried setting FileMode to "fmOpenRead or fmShareDenyNone" but now realise this doesn't apply to text files anyway.
Is there a way of reading text files that are open by another application?
var
f: TextFile;
begin
FileMode := fmOpenRead or fmShareDenyNone; // FileMode IS NOT APPLICABLE TO TEXT FILES!!
AssignFile(f, FileName);
Reset(f);
TStreamReader
to read lines from aTFileStream
. It has aReadLine()
method, and does the buffering internally for you. – KaliTStreamReader
, just open the file with aTFileStream
first with sufficient sharing rights (fmOpenRead or fmShareDenyNone
is usually fine, unless the other handle has exclusive access to the file), and then pass theTFileStream
toTStreamReader
for reading. – Kali