I have the following task. You must wait until the end of editing Microsoft Office files. I use the following normal approach: the file is being edited. While the file is busy:
function FileIsBusy(AFileName: string): Boolean;
var
F: Integer;
begin
F := FileOpen(AFileName, fmShareExclusive);
Result := F = -1;
FileClose(F);
end;
function WaitFile(AFileName: string; ASpeepDelay: integer): Boolean;
begin
while FileIsBusy(AFileName) do
Sleep(ASpeepDelay);
Result := True;
end;
This approach works well with the Microsoft Word editing file, not in Open Office. OpenOffice uses a single process for open multiple files, like MS Office. But there are some problems with OpenOffice Writer: the FileIsBusy function returns false immediately after saving the first OpenOffice Writer file. Any suggestions?
==============================
I find the following solution:
repeat
WaitFile(FFileInfo.lpFile, 333);
Sleep(1000);
until not FileIsBusy(FFileInfo.lpFile);
After saving, the TOE releases the file for some time and again exclusively shares