>>>>I don't want to suggest but I think it may have something to do with the fact that you run app via Citrix. Just a hunch.
>>>
>>>Your problem reminds me of a problem I had on my web server where the program created random files and wanted to delete them, but couldn't. The problem was that the OS didn't let me delete a file immediately after I released all handles to it. My solution was to check for files older than a few minutes and delete them, every time I created a new file.
>>
>>Interesting. I did find out that the problem is indeed in the ERASE (file) code. So, I trap it and also added deletion in form's destroy (also trapped).
>>
>>In the very worse scenario the user will end up with lots of temp files, although I believe we clean this directory when we exit the application.
>
>I always store the temp files locally, and with a characteristic extension or part of the name, so they are easy to distinguish. So a simple adir to find the old files, and a simple loop to delete them, is all you need. As mentioned, I delete the old files in the same procedure I use to create the new temp files.
BTW, trapping ERASE command into try/catch (silently ignore catch case) and also adding erase with try/catch in Destroy method of the form did solve the problem indeed.
Lesson learned - on certain OS you can not immediatelly delete newly created temp file - so, the scenario was exactly as you and Dmitry said - it could be because of the Antivirus program.
If it's not broken, fix it until it is.
My Blog