Homer1779
asked on
Appending data to file; Error I/O 32
Hi all
Last week I was working away on Delphi problem; Data is read in... then we bit of analysis done then a log file is appended.
It worked fine last week, this week I get I/O error message 32. Frankly I am baffled...help!!!! Error report stops on x'd line.
Code Sample
var oneline : string;
fn : textfile;
x,y : integer;
begin
assignfile(fn,'C:\PatientL og2.txt');
append(fn); XXXX Error ReportXXXX
WriteLn(fn,txtPatientNameL og.text);
WriteLn(fn,DateToStr(Date) );
WriteLn(fn,txtMinLog.text) ;
WriteLn(fn,txtMaxLog.text) ;
WriteLn(fn,txtAvgLog.text) ;
CloseFile(fn);
btnSave.visible:=False;
cheers
George
Last week I was working away on Delphi problem; Data is read in... then we bit of analysis done then a log file is appended.
It worked fine last week, this week I get I/O error message 32. Frankly I am baffled...help!!!! Error report stops on x'd line.
Code Sample
var oneline : string;
fn : textfile;
x,y : integer;
begin
assignfile(fn,'C:\PatientL
append(fn); XXXX Error ReportXXXX
WriteLn(fn,txtPatientNameL
WriteLn(fn,DateToStr(Date)
WriteLn(fn,txtMinLog.text)
WriteLn(fn,txtMaxLog.text)
WriteLn(fn,txtAvgLog.text)
CloseFile(fn);
btnSave.visible:=False;
cheers
George
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
mmmmm lizzzard you may have it, will check it out and come back to you
Here only other code that access it...note lack of close!!
assignfile(fn,'C:\PatientL og2.txt');
reset(fn);
while not eof(fn) do
begin
readln(fn,dumPatientName);
readln(fn,dumDate);
readln(fn,DumMin);
readln(fn,DumMax);
readln(fn,DumAvg);
stringgrid1.cells[y,x]:=du mpatientna me;
stringgrid1.cells[y,x]:=du mmin;
stringgrid1.cells[y,x]:=du mmax;
Inc(x);Inc(y);
end;
end;
Here only other code that access it...note lack of close!!
assignfile(fn,'C:\PatientL
reset(fn);
while not eof(fn) do
begin
readln(fn,dumPatientName);
readln(fn,dumDate);
readln(fn,DumMin);
readln(fn,DumMax);
readln(fn,DumAvg);
stringgrid1.cells[y,x]:=du
stringgrid1.cells[y,x]:=du
stringgrid1.cells[y,x]:=du
Inc(x);Inc(y);
end;
end;
Hi,
it is a share-violation or you're trying to a non-existing file. Your program should test these cases like that
var oneline : string;
fn : textfile;
x,y : integer;
OK : Boolean;
begin
assignfile(fn,'C:\PatientL og2.txt');
{$I-}
append(fn);
{$I+}
Ok := IOresult = 0;
If not OK Then
Begin
{$I-}
ReWrite(fn); // File creation if needed
{$I+}
OK := IOResult = 0;
End;
If OK Then
Begin
WriteLn(fn,txtPatientNameL og.text);
WriteLn(fn,DateToStr(Date) );
WriteLn(fn,txtMinLog.text) ;
WriteLn(fn,txtMaxLog.text) ;
WriteLn(fn,txtAvgLog.text) ;
CloseFile(fn);
End; // If Ok
btnSave.visible:=False;
Emmanuel
it is a share-violation or you're trying to a non-existing file. Your program should test these cases like that
var oneline : string;
fn : textfile;
x,y : integer;
OK : Boolean;
begin
assignfile(fn,'C:\PatientL
{$I-}
append(fn);
{$I+}
Ok := IOresult = 0;
If not OK Then
Begin
{$I-}
ReWrite(fn); // File creation if needed
{$I+}
OK := IOResult = 0;
End;
If OK Then
Begin
WriteLn(fn,txtPatientNameL
WriteLn(fn,DateToStr(Date)
WriteLn(fn,txtMinLog.text)
WriteLn(fn,txtMaxLog.text)
WriteLn(fn,txtAvgLog.text)
CloseFile(fn);
End; // If Ok
btnSave.visible:=False;
Emmanuel
ok, i had this problem to(even with a log file ..wierd ha?).
these are my conclutions:
a)it may be disk space.
b)it may be-trying to write/read to the file from 2 diffrent places(meaing 2 procedures trying to call to the same file)
c)try flussing the file before closing it ..
Bye Tomer
these are my conclutions:
a)it may be disk space.
b)it may be-trying to write/read to the file from 2 diffrent places(meaing 2 procedures trying to call to the same file)
c)try flussing the file before closing it ..
Bye Tomer
assignfile(fn,'C:\PatientL og2.txt');
{$I-}
append(fn);
{$I+}
Ok := IOresult = 0;
If not OK Then
Begin
{$I-}
ReWrite(fn); // File creation if needed
{$I+}
OK := IOResult = 0;
End;
can be simplified a bit to -
AssignFile(fn, 'c:\patientLog2.txt');
if FileExists('c:\patientlog2 .txt') then
Append(fn)
else
ReWrite(fn);
I always do that with log files, as some of my users have a bad habit of deleting logs so I can't see what they've been up to!
{$I-}
append(fn);
{$I+}
Ok := IOresult = 0;
If not OK Then
Begin
{$I-}
ReWrite(fn); // File creation if needed
{$I+}
OK := IOResult = 0;
End;
can be simplified a bit to -
AssignFile(fn, 'c:\patientLog2.txt');
if FileExists('c:\patientlog2
Append(fn)
else
ReWrite(fn);
I always do that with log files, as some of my users have a bad habit of deleting logs so I can't see what they've been up to!
ASKER
Thanks for the correct answer Alex and you were fast too!!!
ECollin thanks for your input..... liked what you did there but Alex answered correctly first.
johnstoned I didnt get the point of you posting half of what ECollins posted..... but god loves a chancer.... I dont!!!
thanks all
ECollin thanks for your input..... liked what you did there but Alex answered correctly first.
johnstoned I didnt get the point of you posting half of what ECollins posted..... but god loves a chancer.... I dont!!!
thanks all
I'm delighted!
Cheers,
Alex
Cheers,
Alex
Ciao, Mike