Hello,
I am using
Lazarus 1.8.4 in
Windows 10 Professional x64.
In my form I have a button, that loads a log-file into a TStringlist.
The log file is located in the Windows Log-Folder (C:\WINDOWS\Logs\filename.log) and is created by an other application.
I just read it and show some lines in a TMemo control.
procedure TfrmMainForm.btnRealodLogFileClick(Sender: TObject);
var
LogContent : TStringlist;
begin
// Create the String-List that contains the complete Log-File
LogContent := TStringlist.create;
LogFileName := 'C:\WINDOWS\Logs\filename.log';
// Check if the file exists
if not (FileExists(LogFileName)) then begin
MessageDlg('File not found', 'The following file can not be found:' + #13 + LogFileName, mtError, [mbOK], 0);
// Free the String-List and exit the procedure
LogContent.Free;
Exit;
end;
try
// Try to load the Log-File in the String-List
LogContent.LoadFromFile(LogFileName);
except
on E: EFOpenError do begin
// Error opening the file
MessageDlg('File not accessible', 'The Log-File is not accessible!', mtError, [mbOK], 0);
// Free the String-List and exit the procedure
LogContent.Free;
Exit;
end; // of EFOpenError
end; // of except
// Show the Log-File in the Memo-Control
mmoLogFile.Lines.Clear;
mmoLogFile.Lines := LogContent;
// Free the String List
LogContent.free;
end;
This works without any problems.
But sometimes, when the other application (that is creating the log file) is writing in the file, then I get the
EFOpenError exception.
But why?
I just access it in reading mode!
Or am I wrong?
Best regards
OLLI