Writing to the file on a new line - page 6

 
Aleksei Stepanenko:
Sergei has several Expert Advisors working there, there are several rows, so it's an array. And that is why everything looks ugly. Maxim Kuznetsov suggested SQL, this is the right way for these EAs to communicate with each other.

But the lines are read one by one and somehow the right one is selected. And then you don't need an array.

I said that too, but mql4 does not support SQLite

 

Didn't I plug the library in? Or not there, I forgot.

 
Aleksei Stepanenko:

Didn't I plug the library in? Or not there, I forgot.

It seems that it is not possible to edit a file together at the same time, because the version of the file that was saved later is saved.

For example, program A opened the file for editing, at the same time program B did the same, then program A made the changes and saved them using FileClose, then program B did the same, but when program C opens the file, it will not show the changes made by program A, but only the changes that were implemented and saved by program B, because program B saved the file later than program A.

But this is not certain.

Is there any information on this at all?

 
The simultaneous work of programs with one file is the worst evil. While working on a file, an EA must control the prohibition of other EAs from reading/writing that file. Use SQL or flag-globalvariable or flag-file. Otherwise there will be incomprehensible errors that are hard to detect.
 
Aleksei Stepanenko:
The simultaneous work of programs with one file is the worst evil. At the moment of working with the file, the Expert Advisor should control the prohibition of reading/writing of this file by other Expert Advisors. Use SQL or flag globalvariable or flag file. Otherwise there will be incomprehensible errors that are hard to detect.

It's not that evil, there are all kinds of tasks, you just have to take certain peculiarities into account.

Apparently the changes are saved exactly at the moment of FileClose, and no one is aware of them until then.

 
It's up to you. The human brain is built in such a way that new ideas are hard to come by.
 
EfremovSergey:

It seems that it is not possible to edit a file together at the same time, because the version of the file that was saved later is saved.

For example, program A opened the file for editing, at the same time program B did the same, then program A made changes and saved them using FileClose, then program B did the same, but when program C opens the file, the file will not contain the changes made by program A, but only the changes that program B made and saved, because program B saved the file later than program A.

But this is not certain.

Is there any information on this at all?

It's difficult to set it up, but not impossible. It is enough to check, before saving, time of last change with the same time at opening. We read FILE_MODIFY_DATE, then open the file, make changes, read FILE_MODIFY_DATE again ,compare with the previous one and if no one made changes, close the file and save changes. Otherwise we discard changes... and open it again. Like this.

 
EfremovSergey:

It's not that evil, tasks are different, but there are certain peculiarities that need to be taken into account.

Apparently, the changes are saved at the moment of FileClose, and no one is aware of them until then.

Not a fact.

FileFlush

Reset to disk all data remaining in the file I/O buffer.

void  FileFlush( 
   int  file_handle      // handle файла 
   );
 
Alexey Viktorov:

Difficult to set up, but not impossible. It is enough to check, before writing, time of last change with the same time when you open it. I.e. read FILE_MODIFY_DATE then open file, make changes, again read FILE_MODIFY_DATE compare with previous and if no one made changes, close file saving changes. Otherwise we discard changes... and open it again. Like this.

It's about the same as "busy" flag (first come first served), only times more complicated, but the idea is interesting, I like it, thanks.

 
Alexey Viktorov:

Not a fact.

FileFlush

Reset to disk any data remaining in the file I/O buffer.

Not sure what this means in context of FileClose save.