Delphi File 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 about Stack Overflow the company Business Learn more about hiring developers delphi io error 103 or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x
Delphi File Handling
Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it what is i/o error 103 only takes a minute: Sign up Delphi: Why do I sometimes get an I/O Error 103 with this code? up vote 10 down vote favorite 4 In several of my apps I have code similar to the following: if ForceDirectories(ExtractFilePath(lLogName))
I/o Error 103 Windows 7
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 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 i/o error 103 realterm 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. It happens a lot less often. Most of the time this seems to happen on the first run after I recompiled the application. Could this again be the anti-virus getting in the way? I have only ever seen this happen on my development machine and never gotten a report from a customer. As with the first scenario this only ever happens once per application session (if at all)
Search Advanced Search Go to Page... Thread Tools Display Modes #1 06-13-2002, 02:11 PM MrBaseball34 Senior Member Join Date: Jan 2001 Posts: 7,260 Prevent I/O Error 103 Not used to Std. I/O
What Does I/o Error 103 Mean
operations... When using AssignFile and CloseFile, I am sometimes getting a 103 error (File is
I/o Error 103 Screensaver
not open). How can I check to see if, in fact, the file is open before the CloseFile call? MrBaseball34 View Public i/0 error 103 Profile Visit 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 http://stackoverflow.com/questions/634587/delphi-why-do-i-sometimes-get-an-i-o-error-103-with-this-code 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); 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 http://www.delphipages.com/forum/showthread.php?t=58954 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('File access error', mtWarning, [mbOk], 0); --- Regards /Filip I've lost my autosignature ... *sobbing* ... PoseFant View Public Profile Send a private message to PoseFant Visit PoseFant's homepage! Find all posts by PoseFant #5 06-14-2002, 05:34 AM MrBaseball34 Senior Member Join Date: Jan 2001 Posts: 7,260 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? MrBaseball34 View Public Profile Visit MrBaseball34's homepage! Fi
SpeedVbscriptBatch scriptAssemblyNode.jsObject PascalSQL6502LUAOnline Judgedynamic programming Linux List of Online ToolsScript32Processing ExamplesRaspberry PIAnimationDOSSoftware Engineer Windows ForumForum – New Users / LoginForum – Loss Password / Login SEO, WordPress, Coding for the Web Data Structure https://helloacm.com/delphi-io-error-103/ & Algorithms Shell Scripting & Database Programming LanguagesHow-Tos and Everything Else * HomedelphiDelphi IO Error 103Tags:implementation, object pascal, programming language, tutorial Delphi IO Error 103 https://forum.4programmers.net/Delphi_Pascal/78838-IO_error_103 July 28, 2012 No Comments delphi, I/O File, implementation, technical Similarly to [this], the multithreading in a project has also caused the strange error, which is error 103 IO Error 103. It does not happen every time but randomly. I googled a bit and found this poston stackoverflow.And I started to look into the Delphi code which has the File opening functions using Reset, AssignFile etc. Before, the following function will return the size of a given file.function getFileSizeInBytes(const fn: i/o error 103 string): integer; var f: File of byte; begin Result := -1; if (FileExists(fn)) then begin try AssignFile(f, fn); Reset(f); Result := FileSize(f); finally CloseFile(f); end; end; end;function getFileSizeInBytes(const fn: string): integer; var f: File of byte; begin Result := -1; if (FileExists(fn)) then begin try AssignFile(f, fn); Reset(f); Result := FileSize(f); finally CloseFile(f); end; end; end;The problem occurred most readily when one logging operation swiftly followed another. The second operation would fail for the above reason. To solve the IO 103 error, using the IO directive {$I-} to suppress the exceptions and {$I+} to turn it on. The variable IOResult indicates that the IO operation is successful if it is zero. For example, the above code could be improved using the IOResult.function getFileSizeInBytes(const fn: string): integer; var f: F
Assembler Algorytmy (X)HTML CSS Forum Newbie Delphi/Pascal C/C++ C# i .NET Java Python PHP Webmastering Inne języki programowania Bazy danych Algorytmy i struktury danych Inżynieria oprogramowania Nietuzinkowe tematy Edukacja Kariera Szkolenia i konferencje Magazyn Programista Off-Topic Oceny i recenzje Hardware/Software Społeczność Perełki Projekty Forumowe Flame Ogłoszenia drobne Coyote Test Pastebin Mikroblogi Czat Praca 4programmers.net » Forum » Delphi i Pascal » I/O error 103 I/O error 103 Odpowiedz Nowy wątek lsd100 2005-09-28 18:20 Rejestracja: 2005-09-22 22:36 Ostatnio: 2012-07-14 14:16 Sciagnalem z jakiejs strony przykladowy program na socketach do przesyłania plików. Mam Delphi 7e. Ja mam łacze radiowe a mój znajomy neostrade i podczas testow gdy ja wysylalem z clienta plik do niego ktory mial np.400KB to u niego sciagnelo tylko z 8KB i wyskakiwał błąśI/O error 103. NIe wiemo co chodzi.Gdy sprawdzalem klienta i serwera u siebi ena kompie (127..0.0.1) wszystko bylo ok.A w sieci juz lipa. ZAmieszczam kod Clienta i Serwera : KLIENT -------------------------------------------------- Unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls, ScktComp; type TForm1 = class(TForm) Label1: TLabel; GroupBox1: TGroupBox; Edit1: TEdit; Button1: TButton; GroupBox2: TGroupBox; stat: TStatusBar; od: TOpenDialog; Label2: TLabel; filename: TLabel; Button3: TButton; Button2: TButton; prog: TProgressBar; cmdsock: TClientSocket; filesock: TClientSocket; procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure cmdsockConnect(Sender: TObject; Socket: TCustomWinSocket); procedure cmdsockError(Sender: TObject; Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer); procedure cmdsockDisconnect(Sender: TObject; Socket: TCustomWinSocket); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public d