Delphi Append I/o Error 103
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
Delphi Append File
about Stack Overflow the company Business Learn more about hiring developers or posting ads delphi append to text file with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack delphi append string Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Delphi: Why do I sometimes get an I/O Error 103 with this
What Is I/o Error 103
code? up vote 10 down vote favorite 4 In several of my apps I have code similar to the following: if ForceDirectories(ExtractFilePath(lLogName)) then begin AssignFile(lLog, lLogName); try if FileExists(lLogName) then Append(lLog) else Rewrite(lLog); Writeln(lLog, lLogLine); finally {$I-}CloseFile(lLog);{$I+} end; end; In one application, the first time I try to execute this I consistently get an I/O Error 103 exception on the line with the Append statement (the file does exist
I/o Error 103 Windows 7
prior to calling this). All subsequent attempts at the operation will work fine however - until I restart the app. All the docs I found about this error so far indicated that this would either be caused by calling CloseFile without prior Reset or Rewrite (Append typically isn't mentioned) or if the file was in use by another process. As the exception occurs before the call to CloseFile it obviously couldn't be the former. I already tried inserting a Reset right after the AssignFile for good measure but then I get the exception on that line. There is also no other application overtly accessing that file. I say "overtly" because I do have a slight suspicion that anti-virus (TrendMicro in my case) might be the cuplrit here (so maybe the file is in use). If that was indeed the problem, what would be the best way around it? Hard-coding an automatic retry does not really feel like a clean solution to me... Another case where I sometimes get the 103 error is this code, which I use to create an empty file (or more often to empty an existing file): AssignFile(lFile, AFileName); try Rewrite(lFile); finally CloseFile(lFile); end; In this case it's much harder to reproduce
Search Advanced Search Go to Page... Thread Tools Display Modes #1 06-13-2002, 02:11 PM MrBaseball34 Senior i/o error 103 realterm Member Join Date: Jan 2001 Posts: 7,260 Prevent I/O Error
What Does I/o Error 103 Mean
103 Not used to Std. I/O operations... When using AssignFile and CloseFile, I am sometimes getting a i/0 error 103 103 error (File is not open). How can I check to see if, in fact, the file is open before the CloseFile call? MrBaseball34 View Public Profile Visit http://stackoverflow.com/questions/634587/delphi-why-do-i-sometimes-get-an-i-o-error-103-with-this-code MrBaseball34's homepage! Find all posts by MrBaseball34 #2 06-13-2002, 02:37 PM vandub Member Join Date: Aug 2001 Posts: 44 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)), http://www.delphipages.com/forum/showthread.php?t=58954 mtInformation, [mbOk], 0) else MessageDlg('File access error', mtWarning, [mbOk], 0); vandub View Public Profile Send a private message to vandub Visit vandub's homepage! Find all posts by vandub #3 06-13-2002, 02:37 PM HTML Senior Member Join Date: Jan 2001 Posts: 2,977 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. :-) HTML View Public Profile Send a private message to HTML Visit HTML's homepage! Find all posts by HTML #4 06-13-2002, 10:35 PM PoseFant Senior Member Join Date: Jan 2001 Posts: 1,002 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('Fi
van GoogleInloggenVerborgen veldenZoeken naar groepen of berichten
state. (If the application does not include the System.SysUtils unit, the exception causes the application to terminate). Handling I/O Errors In the {$I-} state, the program continues to execute, and the error is reported by the IOResult function. I/O Error List The following table lists all I/O errors, numbers, and descriptions. Number Name Description 100 Disk read error Reported by Read on a typed file if you attempt to read past the end of the file. 101 Disk write error Reported by CloseFile, Write, WriteIn, or Flush if the disk becomes full. 102 File not assigned Reported by Reset, Rewrite, Append, Rename, or Erase if the file variable has not been assigned a name through a call to Assign or AssignFile. 103 File not open Reported by CloseFile, Read Write, Seek, Eof, FilePos, FileSize, Flush, BlockRead, or BlockWrite if the file is not open. 104 File not open for input Reported by Read, Readln, Eof, Eoln, SeekEof, or SeekEoln on a text file if the file is not open for input. 105 File not open for output Reported by Write or Writeln on a text file if you do not generate a Console application. 106 Invalid numeric format Reported by Read or Readln if a numeric value read from a text file does not conform to the proper numeric format. See Also Exception Handling Resolving Internal Errors (Delphi) Delphi Runtime Errors Fatal errors Operating system errors Retrieved from "http://docwiki.embarcadero.com/RADStudio/Seattle/e/index.php?title=Input-Output_Errors&oldid=227166" Category: RAD Studio ReferenceHidden category: AMMigrate Views Page Discussion View source History Personal tools Create account Log in Search RAD Studio Seattle Seattle Examples and Samples Seattle Libraries Main Page - Seattle Topics Wiki What's New Tutorials FireMonkey Application Platform Multi-Device Applications Getting Started Steps in Developing a Project Key Application Types FireDAC Windows Developer's Guide Modeling Tools IDE Refer