I have a multiple processes which write into same XML file. I am using NativeXML library.
I want to lock my file while any process writes into it so that the data in file should not be overwitten.
I have a multiple processes which write into same XML file. I am using NativeXML library.
I want to lock my file while any process writes into it so that the data in file should not be overwitten.
Copyright © 2021 Jogjafile Inc.
When you create a file, create it with exclusive rights, or at least with write access sharing disabled, then write to it as needed. Nobody else will be able to open the file for writing until you close it first.
In fact, NativeXML already does exactly that when saving XML to a file via its
SaveToFile()
method. It uses aTFileStream
, and that is the default behavior ofTFileSteam
when creating a new file.But, if you need more control over the access rights, then you can create your own
TFileStream
object so you can fill in its constructor parameters as needed. Or create aTHandleStream
object that refers to a file handle that you create using Window'sCreateFile()
API directly. Then you can have NativeXml write to that stream via itsSaveToStream()
method.