Einouterror With Message I O Error 32
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 i/o error 32 game maker this site About Us Learn more about Stack Overflow the company Business delphi io error 103 Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask exception einouterror in module file access denied Question x 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 only takes a minute: Sign
Delphi Assignfile
up Delphi multi-threading file write: I/O error 32 up vote 0 down vote favorite I created a class for writing thread-safe log in a text file using CriticalSection. I am not an expert of CriticalSection and multi-threading programming (...and Delphi), I'm definitely doing something wrong... unit ErrorLog; interface uses Winapi.Windows, System.SysUtils; type TErrorLog = class private FTextFile : TextFile; FLock : TRTLCriticalSection; public constructor Create(const aLogFilename:string); destructor Destroy; override; procedure Write(const ErrorText: string); end; implementation constructor TErrorLog.Create(const aLogFilename:string); begin inherited Create; InitializeCriticalSection(FLock); AssignFile(FTextFile, aLogFilename); if FileExists(aLogFilename) then Append(FTextFile) else Rewrite(FTextFile); end; destructor TErrorLog.Destroy; const fmTextOpenWrite = 55218; begin EnterCriticalSection(FLock); try if TTextRec(FTextFile).Mode <> fmTextOpenWrite then CloseFile(FTextFile); inherited Destroy; finally LeaveCriticalSection(FLock); DeleteCriticalSection(FLock); end; end; procedure TErrorLog.Write(const ErrorText: string); begin EnterCriticalSection(FLock); try WriteLn(FTextFile, ErrorText); finally LeaveCriticalSection(FLock); end; end; end. to test the class I created a form with a timer set to 100 milliseconds: procedure TForm1.Timer1Timer(Sender: TObject); var I : integer; aErrorLog : TErrorLog; begin aErrorLog := nil; for I := 0 to 1000 do begin try aErrorLog := TErrorLog.Create(FormatDateTime('ddmmyyyy', Now) + '.txt'); aErrorLog.Write('new line'); finally if Assigned(aErrorLog) then FreeAndNil(aErrorLog); end; end; end; the logs are written, but occasionally raise I/O Error 32 exception on CloseFile(FTextFile) (probably because in use in another thread) where am I doing wrong? UPDATE: after reading all the comments and the answers I have totally changed approach. I share my solution. ThreadUtilities.pas (* Implemented for Delphi3000.com Articles, 11/01/2004 Chris Baldwin Director & Chief Architect Alive Technology Limited http://www.alivetechnology.com *) unit ThreadUtilities; interface uses Windows, SysUtils, Classes;
Advanced Search Go to Page... Thread Tools Display Modes #1 03-06-2002, 02:34 AM Dracula Junior Member Join Date: Mar 2002 Posts: 7 I/O error 32 ??? Hi, I'm building a tool in Delphi to view history log files of another program. There's no problem when I open such files using an untyped file variable. But since I want to parse the history one line at a time, I really want to open them as 'textfile'. But when I do so, an I/O error 32 occurs on the statement "Reset(F)" I've searched the help pages and on the internet, but can't find anything about what this http://stackoverflow.com/questions/27202975/delphi-multi-threading-file-write-i-o-error-32 error means. At the moment, I'm using this trick to copy the entire file using the untyped file variable, and then open the copy as textfile. But since the files can become really big and I simply want to know what's happening, I'd like to fix the problem more elegantly Other effects on the history files: DeleteFile(..) results in False when the history file is opened by the other program (sounds logical), however I http://www.delphipages.com/forum/showthread.php?t=47739 can open the file and truncate it at the first byte But then, next time I try to open it, my viewer crashes (application error)... I know it's not very nice to truncate an open file, probably the other program doesn't even know it happened, and thus writes at the wrong locations... In conclusion: this is my question: what does "I/O error 32" mean? Kind regards, Sebastian Groeneveld Dracula View Public Profile Send a private message to Dracula Visit Dracula's homepage! Find all posts by Dracula #2 03-06-2002, 04:39 AM andyho Senior Member Join Date: Jul 2001 Posts: 1,446 RE: I/O error 32 ??? IO error 32 means "sharing violation" - the file you're trying to open is already open, either you forgot the closefile earlier, or a second application is using it. Bye, Andy andyho View Public Profile Visit andyho's homepage! Find all posts by andyho #3 03-06-2002, 04:48 AM GoodFun Senior Member Join Date: Jan 2001 Posts: 2,645 RE: I/O error 32 ??? Hi there, I strongly suggest you change from the "old" Assign file method to TFileStreams. They are by factors faster and you can do everything you need with them as easy as with a File variable. This is an example how to use TFileStreams: var DebugLog: TFileStream; procedure TPowerTr
= class(Exception); C++ class EInOutError : public Exception; File SysUtils Description EInOutError is raised when an file input/output error occurs, provided I/O checking is enabled. Note: In Delphi code, use the $I+ directive to enable I/O checking. http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/SysUtils_EInOutError.html If an I/O error occurs while this directive is disabled, the application must call IOResult to clear the error. Note: In C++ programs, I/O checking is a project option. The error code is available in the http://delphi-techie.faithweb.com/rich_text_4.html ErrorCode class member. Error codes are come in ranges: 0-99 (native OS errors) Error codes in the range 0-99 represent OS error conditions, which are different for Windows and Linux. Refer to the OS documentation o error for complete error summaries. The SysErrorMessage function returns descriptive text for OS errors. Here are some common OS I/O errors, arranged by rough equivalents in Linux and Windows: LinuxWindows Linux Windows Error Code Description Error Code Description 2 No such file or directory 2 File not found 3 Path not found 5 I/O Error o error 32 13 Permission denied 5 Access denied 20 Not a directory 21 Is a directory 32 Sharing violation Error codes in the range 100 to 149 represent error conditions raised by CLX. Here are the CLX I/O error codes: Error code Meaning 100 End of File 101 Disk Full 102 File variable not assigned 103 File not open 104 File not open for input 105 File not open for output 106 Error in formatted input 107 File already open Delphi Examples: Copy Code { Click the button to open a TOpenDialog, then select a file to delete. } procedure TForm1.Button1Click(Sender: TObject); var F: Textfile; begin OpenDialog1.Title := 'Delete File'; if OpenDialog1.Execute then begin AssignFile(F, OpenDialog1.FileName); try Reset(F); if MessageDlg('Erase ' + OpenDialog1.FileName + '?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin CloseFile(F); Erase(F); end; except on EInOutError do MessageDlg('File I/O error.', mtError, [mbOk], 0); end; end; end; See Also IOResult EStreamError SysErrorMessage Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved. What do you think about this topic? Send feedback!
DllForms SqlCommands XML XML Extension API MessageBox API DELPHI MemoryLeakage I|OERROR GuestBook Malai Appendix A - Delphi I/O ErrorsThanks goes out to Erik Martin for posting these Delphi IO errors on his web site. The following are the Windows API (and former DOS) IO errors, which are also the IO errors often returned by Delphi programs, and which are generally difficult to find reference for, and are especially difficult to find referenced as Delphi errors.Some of the high-numbered sections toward the end contain Windows API errors which are not truely be IO errors, but which may or may not be reported as such in programs.I/O Error 1:// IO Error 1L// ERROR_INVALID_FUNCTION // MessageText:// Incorrect function.I/O Error 2:// IO Error 2L// ERROR_FILE_NOT_FOUND// MessageText:// The system cannot find the file specified.I/O Error 3:// IO Error 3L// ERROR_PATH_NOT_FOUND// MessageText:// The system cannot find the path specified.I/O Error 4:// IO Error 4L// ERROR_TOO_MANY_OPEN_FILES// MessageText:// The system cannot open the file.I/O Error :5// IO Error 5L// ERROR_ACCESS_DENIED// MessageText:// Access is denied.I/O Error 6:// IO Error 6L// ERROR_INVALID_HANDLE// MessageText:// The handle is invalid.I/O Error 7:// IO Error 7L// ERROR_ARENA_TRASHED// MessageText:// The storage control blocks were destroyed.I/O Error 8:// IO Error 8L// ERROR_NOT_ENOUGH_MEMORY// MessageText:// Not enough storage is available to process this command.I/O Error 9:// IO Error 9L// ERROR_INVALID_BLOCK// MessageText:// The storage control block address is invalid.I/O Error 10:// IO Error 10L// ERROR_BAD_ENVIRONMENT// MessageText:// The environment is incorrect.I/O Error 11:// IO Error 11L// ERROR_BAD_FORMAT// MessageText:// An attempt was made to load a program with an// incorrect format.I/O Error 12:// IO Error 12L// ERROR_INVALID_ACCESS// MessageText:// The access code is invalid.I/O Error 13:// IO Error 13L// ERROR_INVALID_DATA// MessageText:// The data is invalid.I/O Error 14:// IO Error 14L// ERROR_OUTOFMEMORY// MessageText:// Not enough storage is available to complete this operation.I/O Error 15:// IO Error 15L// ERROR_INVALID_DRIVE// MessageText:// The system cannot find the drive specified.I/O Error 16:// IO Error 16L// ERROR_CURRENT_DIRECTORY// MessageText:// The directory cannot be removed.I/O Error 17:// IO Error 17L// ERROR_NOT_SAME_DEVICE// MessageText:// The system cannot move the file// to a different disk drive.I/O Error 18:// IO Error 18L// ERROR_NO_MORE_FILES// MessageText:// There are no more files.I/O Error 19:// IO Error 19L// ERROR_WRITE_PROTECT// MessageText:// The media is write protected.I/O Error 20:// IO Error 20L// ERROR_