Recent

Author Topic: TMemoryStream.SaveToFile exceptions....  (Read 2049 times)

Prime

  • Jr. Member
  • **
  • Posts: 62
TMemoryStream.SaveToFile exceptions....
« on: February 20, 2018, 11:39:02 am »
Hi all,

I'm writing a program to manipulate disk image files that will be used with retro computer emulators. My program loads the disk image into a TMemoryStream with LoadFromFile, does some operation on it, such as list, read or write files. Once the operation is complete, if it was a write it attempts to use SaveToFile to write it back to the disk file.

This unfortunately seems to lead to a EFCreateError about 25% of the time. The odd thing is if I retry the operation it will work. The file is not read only (as it was created initially by my program anyway). Also annoyingly if I run the program in Lazarus, single stepping it always works :)

My environment is Windows 7 x64, Lazarus 1.8.0. FPC 3.0.4. I don't currently have any addon components, so just a vanilla Lazarus install.

Anyone have any clues as to what is going on here?

My test batch file :

Code: Pascal  [Select][+][-]
  1. dfsdisk create test.ssd -t 80 -q $20
  2. dfsdisk write test.ssd -f ../System-ROM/FORM40 -q $20 -l $2800 -e $2800
  3. dfsdisk write test.ssd -f ../System-ROM/FORM80 -q $20 -l $2800 -e $2800
  4. dfsdisk write test.ssd -f ../System-ROM/VERIFY4 -q $20 -l $2800 -e $2800
  5. dfsdisk write test.ssd -f ../System-ROM/VERIFY8 -q $20 -l $2800 -e $2800
  6.  

My Test output :
Code: Pascal  [Select][+][-]
  1. C:\Users\phill\Dropbox\AtomDOS\DFSDisk>test
  2.  
  3. C:\Users\phill\Dropbox\AtomDOS\DFSDisk>dfsdisk create test.ssd -t 80 -q $20
  4. Created image file test.ssd, title , qual  , opt 0
  5.  
  6. C:\Users\phill\Dropbox\AtomDOS\DFSDisk>dfsdisk write test.ssd -f ../System-ROM/FORM40 -q $20 -l $2800 -e $2800
  7. StreamIn.size=512
  8. Saving to test.ssd
  9. Wrote file ../System-ROM/FORM40 to DFS:FORM40  on image test.ssd
  10.  
  11. C:\Users\phill\Dropbox\AtomDOS\DFSDisk>dfsdisk write test.ssd -f ../System-ROM/FORM80 -q $20 -l $2800 -e $2800
  12. StreamIn.size=512
  13. Saving to test.ssd
  14. Exception at 00411191: EFCreateError:
  15. Unable to create file "test.ssd".
  16.  
  17. C:\Users\phill\Dropbox\AtomDOS\DFSDisk>dfsdisk write test.ssd -f ../System-ROM/VERIFY4 -q $20 -l $2800 -e $2800
  18. StreamIn.size=294
  19. Saving to test.ssd
  20. Wrote file ../System-ROM/VERIFY4 to DFS:VERIFY4 on image test.ssd
  21.  
  22. C:\Users\phill\Dropbox\AtomDOS\DFSDisk>dfsdisk write test.ssd -f ../System-ROM/VERIFY8 -q $20 -l $2800 -e $2800
  23. StreamIn.size=294
  24. Saving to test.ssd
  25. Exception at 00411191: EFCreateError:
  26. Unable to create file "test.ssd".
  27.  

Cheers.

Phill.

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: TMemoryStream.SaveToFile exceptions....
« Reply #1 on: February 20, 2018, 11:48:13 am »
YIKES. C:\Users\phill\Dropbox\AtomDOS\DFSDisk

Did you try this OUTSIDE your dropbox?
When dropbox uploads changed files it will lock that file !!

(I've come across this myself  8-))

Thaddy

  • Hero Member
  • *****
  • Posts: 14367
  • Sensorship about opinions does not belong here.
Re: TMemoryStream.SaveToFile exceptions....
« Reply #2 on: February 20, 2018, 11:58:34 am »
Indeed. Even your OS will - locally - lock that file... But the speed of the connection makes it visible. >:( These are computing basics.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

Prime

  • Jr. Member
  • **
  • Posts: 62
Re: TMemoryStream.SaveToFile exceptions....
« Reply #3 on: February 20, 2018, 02:13:55 pm »
YIKES. C:\Users\phill\Dropbox\AtomDOS\DFSDisk

Did you try this OUTSIDE your dropbox?
When dropbox uploads changed files it will lock that file !!

(I've come across this myself  8-))

Ahhh yes of course, that makes sense, tried writing the file to c:\tmp\ and it works without problems. Glad to know it's not my code :)

Cheers.

Phill.

 

TinyPortal © 2005-2018