I/O error 32 when manipulating files

hi, when I did the coding to manipulate the file, i also met I/O error, the problem occurs when hitting the following command:
  Rewrite(tempfile);
I am using windows 2000 and Delphi 6.0. Please tell me what happens and how to solve this problem!!!
Thanks
cdbdelphiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MotazCommented:
Please post your code that generate the error, then we can help.
I/O errors has alot of meansings
Motaz
0
intheCommented:
hi,
rewrite creates and opens a file ,
i/o 32 error is a "sharing violation"
(ie the file is already opened.)

so it sounds like you already opened the file, maybe using filecreate(),if that is the case then use fileclose() before calling rewrite()

example from help on rewrite usage:

var F: TextFile;

begin
  AssignFile(F, 'NEWFILE.$$$');
  Rewrite(F);
  Writeln(F, 'Just created file with this text in it...');
  CloseFile(F);
end;


if you still have problems post you code here
0
BudaCommented:
The win32 errorcode nr 32:

ERROR_SHARING_VIOLATION
The process cannot access the file because it is being used by another process.
0
maioCommented:

The error is a sharing violation, which can mean that your or another program has this files opened. For a <rewrite> you'll need of course exclusive rights, so the error has to occur, if there's something wrong.
Of course, if your program had opened the file before, you will have to close it, but maybe there's another program - in that case you only can prevent that ugly error-message by checking if your <rewrite> is possible.
Therefore you can disable the error-check temporarily :

 {$I-} // I/O-checking OFF
 Rewrite(F);
 {$I+} // I/O-checking ON - you should let it on elsewhere
 if Ioresult<>0 then begin
   // the file couldnt be created
 end else begin
   // all ok, file is rewritten
 end


 Writeln(F, 'Just created file with this text in it...');
 CloseFile(F);
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cdbdelphiAuthor Commented:
Thanks a lot for you guys help! I try to solve that problem and I learn a lot more than the problem itself. It is a great place to get what I want to know...
rgds
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.