Thaddy, I know that "= true" is not necessary but I've written code in that old version of Lazarus in which leaving it out caused problems so I acquired the habit of being redundant in this case ever since. It doesn't hurt anything.
As for InOutRes, I assume that what you are saying is that it has to be used with each delete or other such operation.
I plan to wait until the text file problem happens again before I try this solution so that I know whether or not it fixes the error, else I might end up wondering if I fixed it or not. I'll use something like what is shown below when the problem happens again.
Thanks for your reply and thanks for the code that tests if a file is open or not. I've never seen that before and I'll keep it in mind.
procedure TForm1.Button25Click(Sender: TObject);
begin
InOutRes := 0;
DeleteFile('image5.txt');
if FileExists('image5.txt') = true then
memo2.text := 'The deletion failed.'
else
memo2.text := 'The deletion succeeded.';
end;