Darksoul71
31st October 2002, 11:50
Hi there,
No this thread has nothing to do with video related programming :D
this question goes out to the more experienced Delphi programers out there.
Iīm currently writting a text analysys tool for my dimploma at university.
Iīve been using the following IO error checking for nearly all my programs:
//---------------------------
....
//Disable IOChecking
{$I-}
// Do an IO operation
ReadLn ()
//Enable IOChecking
{$I+}
// Check for errors
If (IOResult=0) Then
Begin
// Do some stuff :)
End
// stop on error
else break;
...
//---------------------------
This works fine for simple program where you only open up a single text file. Now I have to
open, close, read, write, etc tons of text files with sizes up to 600 MB. So debugging this is a real pain in the a$$.
A friend of mine suggested to use try...except...else...end
Here a small snippet of my code:
//------------------------------------------------------------------------------
Procedure ErrorLog(Fehler : Integer;Datei : String; Prozedur : String);
Var L : TextFile;
Begin
If (Fehler <> 0) And (Form1.CheckBox2.Checked) Then
Try
AssignFile(L,Form1.Edit13.Text);
If FileExists(Form1.Edit13.Text) Then Reset(L)
Else Rewrite(L);
Except
// Exceptionhandling
Else
Try
// Go on if no error occured
WriteLn(L,'---------------------------------');
WriteLn(L,'Zeit: '+TimeToStr(Time));
WriteLn(L,'Prozedur: '+Prozedur);
WriteLn(L,'Datei: '+Datei);
WriteLn(L,'IO Fehler: '+IntToStr(Fehler));
Except
// Exceptionhandling
Else
CloseFile(L);
End;
End;
End;
//------------------------------------------------------------------------------
Although this worked fine previously with the {$I-} stuff it just drops
back to the end of the file although the error log file should be ok.
I donīt get this.
Has anyone of you experiences with except...end etc. ?
If so, how do I check of IO errors ? How can I get the IO error if an exception occured ?
I would be very happy if some1 could post some sample code for safely accessing textfiles with this try..except stuff. May be with some error handling ?
TIA,
D$
No this thread has nothing to do with video related programming :D
this question goes out to the more experienced Delphi programers out there.
Iīm currently writting a text analysys tool for my dimploma at university.
Iīve been using the following IO error checking for nearly all my programs:
//---------------------------
....
//Disable IOChecking
{$I-}
// Do an IO operation
ReadLn ()
//Enable IOChecking
{$I+}
// Check for errors
If (IOResult=0) Then
Begin
// Do some stuff :)
End
// stop on error
else break;
...
//---------------------------
This works fine for simple program where you only open up a single text file. Now I have to
open, close, read, write, etc tons of text files with sizes up to 600 MB. So debugging this is a real pain in the a$$.
A friend of mine suggested to use try...except...else...end
Here a small snippet of my code:
//------------------------------------------------------------------------------
Procedure ErrorLog(Fehler : Integer;Datei : String; Prozedur : String);
Var L : TextFile;
Begin
If (Fehler <> 0) And (Form1.CheckBox2.Checked) Then
Try
AssignFile(L,Form1.Edit13.Text);
If FileExists(Form1.Edit13.Text) Then Reset(L)
Else Rewrite(L);
Except
// Exceptionhandling
Else
Try
// Go on if no error occured
WriteLn(L,'---------------------------------');
WriteLn(L,'Zeit: '+TimeToStr(Time));
WriteLn(L,'Prozedur: '+Prozedur);
WriteLn(L,'Datei: '+Datei);
WriteLn(L,'IO Fehler: '+IntToStr(Fehler));
Except
// Exceptionhandling
Else
CloseFile(L);
End;
End;
End;
//------------------------------------------------------------------------------
Although this worked fine previously with the {$I-} stuff it just drops
back to the end of the file although the error log file should be ok.
I donīt get this.
Has anyone of you experiences with except...end etc. ?
If so, how do I check of IO errors ? How can I get the IO error if an exception occured ?
I would be very happy if some1 could post some sample code for safely accessing textfiles with this try..except stuff. May be with some error handling ?
TIA,
D$