Re: debug Delphi: I/o error 6 and 32

Posted by webmaster Guido on March 03, 2007

In Reply to I/o error 6 and I/O error 32 posted by Jan Dunn-p12534 on February 27, 2007

: I have a short program that reads some text files then encrypts them. I occasionally get I/O error 6 or 32. Heres my code:

: [source code here, see previous message]

Let's start by looking at what these errors mean.

I/O error code 6 means "INVALID FILE HANDLE". In order of probability, that's because:

1. You're trying to use a file that doesn't exist;
2. You're trying to use a file that you haven't opened yet;
3. Or you're trying to use a file that you have already closed;
4. Or you're trying to read more data than your buffer can hold;
5. Or something else.

I/O error 32 means "SHARING VIOLATION", in other words: you're trying to access a file which is in use by some other process (in your program or "locked" by another application).

Because the errors only show up occasionally, I'm guessing that there is either a timing problem in run-time, or maybe sometimes a file is not found because of a programming error. So, let's try to narrow it down:

- After which line do you receive error code 6?
Load your project in the Delphi IDE, and add a debugging "breakpoint" in your source code, a little bit before the place where you expect an error to happen. Next, launch the program by pressing key F9.
If you receive an error code 6 before the program halts on the breakpoint, then remove the breakpoint and set a new breakpoint a bit "earlier". Continue doing this until you find out after which line the error code 6 happens. Then, let us know :)

- At which line do you receive error code 32?
Using the same strategy as above, try to find out after which source code line you are receiving an error code 32.

I know that this "trial and error" method can be quite time consuming, but sometimes it's the best you've got available... In the mean time, we'll simulate your application, maybe we get the same errors.

Please let me know the results of your tests!
Good luck!
Guido

Related articles

       

Follow Ups