Can't delete file after writing lazarus / 39-Graphics ---------------------------------------------------------------------- jave · 2018-10-15 06:42 Hi all, Newbie here so please be gentle. :-) I've written some code to do some very basic edge detection.  I can load the bitmap file successfully using Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i BitMap1 := Graphics.TBitMap.create;Bitmap1.Loadfromfile(Edit1.Text); I then process the image and save to a file using Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i BitMap1.SaveToFile(Edit2.Text); I then exit the program.  Problem is, when I try to delete the saved image file from Windows, I'm unable to.  Any ideas?  I think it's something to do with the file still being open, but not sure.  Thanks! ---------------------------------------------------------------------- Thaddy · 2018-10-15 07:03 Bitmap1.free would solve that probably, or closing your application first. ---------------------------------------------------------------------- jave · 2018-10-15 07:32 Ok, thanks!  Where do I add "BitMap1.Free" - after saving? ---------------------------------------------------------------------- Thaddy · 2018-10-15 09:36 No idea. You didn't show us your code. I don't know if you created the bitmap in code for example... ---------------------------------------------------------------------- jave · 2018-10-15 09:53 No problem. See code below. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  If FileExists(Edit2.Text) then begin     Label6.Caption := 'File exists. Enter new filename.';  end  else begin       BitMap1.SaveToFile(Edit2.Text);       BitMap1.Free;  end;end; procedure TForm1.Button2Click(Sender: TObject);begin  BitMap1 := Graphics.TBitMap.create;  Bitmap1.Loadfromfile(Edit1.Text);  Label6.Caption := 'File loaded.';end; ---------------------------------------------------------------------- Thaddy · 2018-10-15 12:45 Looks fine to me. Still having problems? If you are repeating the operation you may try - just for debugging - FreeAndNil(Bitmap1). If that works there is a bug in the bitmap sources, because it shouldn't be necessary: after the internal filestream is released, the file should not have any locks. ---------------------------------------------------------------------- marcov · 2018-10-15 13:05 How long after do you test? It could be an antivirus that is still keeping it locked. Usually locks don't immediately disappear after a write (or directory mutation) operation, but usually they go away in 100ms of ms. If it is more, it is usually the antivirus. ---------------------------------------------------------------------- jave · 2018-10-16 09:22 Hmmm.. program now works as expected.  Thanks to all for your help!