Example code : Try to delete a file twice
var
  fileName : string;
  myFile   : TextFile;
  data     : string;

begin
  // Try to open a text file for writing to
  fileName := 'Test.txt';
  AssignFile(myFile, fileName);
  ReWrite(myFile);

  // Write to the file
  Write(myFile, 'Hello World');

  // Close the file
  CloseFile(myFile);

  // Reopen the file in read mode
  Reset(myFile);

  // Display the file contents
  while not Eof(myFile) do
  begin
    ReadLn(myFile, data);
    ShowMessage(data);
  end;

  // Close the file for the last time
  CloseFile(myFile);

  // Now delete the file
  if deletefile(fileName)
  then ShowMessage(fileName+' deleted OK')
  else ShowMessage(fileName+' not deleted');

  // Try to delete the file again
  if deletefile(fileName)
  then ShowMessage(fileName+' deleted OK again!')
  else ShowMessage(fileName+' not deleted, error = '+
                   IntToStr(GetLastError));
end;