Delphi - Sharing violation opening text file -


I am trying to open a text file to read in the Delphi 7 app, but I / O error is getting 32 (Sharing violation) because the file has already been opened in another application, I tried to set the file to "fmOpenRead or fmShareDenyNone" but now it seems that this text does not apply to any file.

Is there a way to read text files that are open by another application?

  var f: textfile; Start filemodel: = fmOpenRead or fmShareDenyNone; // File Max Text files do not apply !! Assign file (f, filename); (F) reset;    

Use the LoadFromStream method of TStringList, instead of LoadFromFile . You can control locking in such a way:

  var slFile: TStrings; Stream: TSTream; Start Slafile: = TStringList.Create; Try the stream: = TFileStream.Create (file name, fmOpenRead or fmShareDenyNone); Try slFile.LoadFromStream (stream); Finally stream. free; End; // stringlist Finally slFile.Free; End; End; This example is using the stream to load in a  TStringList . If you just want to read the pieces, you can do this. Just read from the stream. 


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -