Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a file that is in use by other process?

Tags:

winapi

delphi

I have an application that have a log system that create a file and keep it handle with a TFileStream, that is created with this way:

FFileStream := TFileStream.Create(FFilename, fmOpenWrite);

Ok. When I try to open this file with notepad, no problem, with notepad++ no problem. When I try to load the file with other application that I created it raise my an error that says the file is in used by other process.

I tried TStringList, LoadFromFile and TFileStream.Create(LFile, fmOpenRea);.

Some one knows how I can read this like the notepad and notepad++?

like image 733
Rodrigo Farias Rezino Avatar asked Oct 21 '25 07:10

Rodrigo Farias Rezino


2 Answers

Erik got there first but uses fmShareDenyNone which would allow other processes to write to the same file. If you only want to allow reading by other processes, use:

FFileStream := TFileStream.Create(FFilename, fmOpenWrite or fmShareDenyWrite);
like image 183
Marjan Venema Avatar answered Oct 23 '25 22:10

Marjan Venema


Use fmOpenWrite or fmShareDenyNone to enable sharing.

like image 39
Erik Avatar answered Oct 23 '25 23:10

Erik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!