Exclusive lock on excel file

Questions and answers on how to use XLSReadWriteII 5.
Post Reply
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Exclusive lock on excel file

Post by d3nton »

Hi!

Is there a way (option or property or s.th.) to exclusively lock an excel file when beginning to read the file via TXLSReadWriteII5.Read until it is written again?
I currently run into a problem where two program instances try to write into the same excel file. First both instances have read the file (into memory) and did some modifications
but then override each other when writing into the same file. Is there a way to lock the excel file before the first instance starts reading until it has written its modifications into the file?

best regards
larsa
Site Admin
Posts: 926
Joined: Mon Jun 27, 2005 9:30 pm

Re: Exclusive lock on excel file

Post by larsa »

Hello

You have to modify the source for this. Open file XLSReadWriteII5 and go to line #827 (Stream := TFileStream.Create(FManager.Filename,fmOpenRead or fmShareDenyNone);)
Change the share options to what you want.
Lars Arvidsson, Axolot Data
d3nton
Posts: 133
Joined: Thu Oct 25, 2012 9:48 am

Re: Exclusive lock on excel file

Post by d3nton »

Hi again.

I came across this problem again. The described approach does not work because 'Stream' is a local variable that is released at the end of the function. I would need a way to lock the file from the outside, so that it is only released after the file has been written. Is that possible?
Post Reply