Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-13-2002, 02:11 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default Prevent I/O Error 103

Not used to Std. I/O operations...

When using AssignFile and CloseFile, I am sometimes
getting a 103 error (File is not open).

How can I check to see if, in fact, the file is open
before the CloseFile call?
Reply With Quote
  #2  
Old 06-13-2002, 02:37 PM
vandub vandub is offline
Member
 
Join Date: Aug 2001
Posts: 44
Default RE: Prevent I/O Error 103

you could use the {$i-}
command then check the ioresult for an error

AssignFile(F, FileName);
{$I-}
Reset(F);
{$I+}
if IOResult = 0 then
MessageDlg('File size in bytes: ' + IntToStr(FileSize(F)),
mtInformation, [mbOk], 0)
else
MessageDlg('File access error', mtWarning, [mbOk], 0);
Reply With Quote
  #3  
Old 06-13-2002, 02:37 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Prevent I/O Error 103

Hello,

This site has many examples on File I/O and uses IoResult(should return 0 if successfull) in few places in the snippets.

http://homepages.borland.com/efg2lab/Library/Delphi/IO/FileIO.htm

If perhaps you can post a snippet of your code that you think cuases the problem , that would help.

:-)
Reply With Quote
  #4  
Old 06-13-2002, 10:35 PM
PoseFant PoseFant is offline
Senior Member
 
Join Date: Jan 2001
Posts: 1,002
Default RE: Prevent I/O Error 103

you could use the {$i-}
command then check the ioresult for an error

AssignFile(F, FileName);
{$I-}
Reset(F);
{$I+}
if IOResult = 0 then
MessageDlg('File size in bytes: ' + IntToStr(FileSize(F)),
mtInformation, [mbOk], 0)
else
MessageDlg('File access error', mtWarning, [mbOk], 0);


---

Regards

/Filip

I've lost my autosignature ... *sobbing* ...
Reply With Quote
  #5  
Old 06-14-2002, 05:34 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Prevent I/O Error 103

Hey, Filip, did you just simply copy vandub's post verbatim?

Anyway...

I want to know how to determine if the file is open before
I call FileClose. If I use Reset, what will happen to the
file if it IS open?
Reply With Quote
  #6  
Old 06-14-2002, 10:23 AM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Prevent I/O Error 103

Hello, MB34 :-)

Here are just a few situations where you might get a I/O Error 103. Compiled from many sources on the Google Newsgroups(There are many people who seem to get this error).

1)Either you forgot to use Reset or Rewrite after AssignFile

2)An easy way to get this error is to do a

writeLN( varname );

instead of

writeLn( file, varname );

3) Use either Rewrite or Reset , dont call them right after eachother.

Rewrite(Test);
Reset(Test);

4)Consider the following ,

assignfile(outfile, 'C:\out.txt');
reset(outfile);
writeln(outfile, lblscore.caption);
closefile(outfile);

When you use Reset, don't forget that your cusrsor isn't at the end of the
file (EOF). Try Appen(outfile) in place of reset, it will place the cursor
after the last entry and you will be able to add some more entries.

Also have a look here,
http://makeashorterlink.com/?F23B52F01


Hope this help, Best Regards :-)
Reply With Quote
  #7  
Old 06-14-2002, 10:57 AM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Prevent I/O Error 103

I used vandub's suggestion but I am still getting the error.
I can't find the place that it is actually happening.

I know the file is being closed but then as the form is
closed, the error occurs...
Reply With Quote
  #8  
Old 06-14-2002, 12:08 PM
HTML HTML is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,977
Default RE: Prevent I/O Error 103

Hello, :-)

Is it possible you can post a snippet?

Or did you try to make a little test application, and see if it happens there.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:27 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.