Link to home
Start Free TrialLog in
Avatar of chrisbee
chrisbee

asked on

File Access Denied error

Since I deleted my last question, because of the need to read more to understand what the experts give out, I have come across this particular problem several times. I put clip Of my code here which goes as follows-

writeln('save these details (Y/N)?);
readln(reply);
if (reply='y') or (reply='Y')
then
   Newrec.TranNo:= Newrec.TranNo+1;
   Newrec.InDel:=false;
   write(Inco,Newrec);<-'file access denied' error flagged here
 writeln('do you wish to continue?(Y/N)');
  readln(reply);
until (reply='n') or (reply='N');
close(Inco);
end;

The file is opened up as usual at the beginning of the procedure and the contents of the file seeked ie;

seek(InCo,Filesize(InCo)-1);
if not eof(InCo)
then
read(InCo,Newrec);

then the data is entered, when the request is made to save, then the file access error aboughts the program.
Why should this be as the record has to be written to file; write(InCO,Newrec);
Thanks for your help...chrisbee.



ASKER CERTIFIED SOLUTION
Avatar of Hypo
Hypo
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbrunton
Presumably you have something like

type
  DataRecord = record
    TranNo : integer;
    InDel : boolean
  end;

var
 Inco : file of DataRecord;
 EndOfTheFile : longint;
 TheData, NewRec : DataRecord;

assign(Inco, 'FILENAME');
reset(Inco);


EndOfTheFile := FileSize(Inco) div SizeOf(TheDataRecord);
Seek(Inco, EndOfFile);   {* this gives you end of file *}



{* code should be something like this *}

writeln('save these details (Y/N)?);
readln(reply);
repeat
  begin
      if (reply='y') or (reply='Y') then
         begin
            Newrec.TranNo := Newrec.TranNo+1;
            Newrec.InDel := false;
            write(Inco, Newrec);  <-'file access denied' error flagged here
          end;
      writeln('do you wish to continue?(Y/N)');
      readln(reply);
  end;
until (reply='n') or (reply='N');
Avatar of chrisbee
chrisbee

ASKER

HiHypo!

Nice to hear from you again. Thanks for your help. I tried the code you suggested and the error has gone. I applied this to the other files inwhich the same error arose and they too are now ok. I can now get on with the final procedure in my prog. I shall have a go myself but it seems likely I shall have to return to 'EE' with yet another question but this time I shall post up the code here for all to see. My Thanks to all those who offered help- I wish I could give you all some points

Best wishes.........chrisbee.