Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File Access Denied error

Posted on 2000-02-22
3
Medium Priority
?
216 Views
Last Modified: 2010-04-16
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.



0
Comment
Question by:chrisbee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
Hypo earned 400 total points
ID: 2549418
The reason you get that error is most probably because your file is opened as READ-ONLY. i don't know how you open your file but this is how I'm dooing it.
And I can write records to a file without getting that error.

uses crt,dos;

var NewRec : NewRecType;
    InCo : File of NewRecType;

begin
 assign(InCo,'FileName.Any');
 Reset(InCo);
 Seek(InCo,FileSize(InCo)-1);
 if not EOF(InCo) then Read (InCo,NewRec);
 {...}
 Write(InCo,NewRec);
 Close(InCo);
end.

This piece of code works on my computer. Try it on yours and see if it works... if it does, check out what differs between yours and mine!

regards, Hypo
0
 
LVL 49

Expert Comment

by:dbrunton
ID: 2549423
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');
0
 

Author Comment

by:chrisbee
ID: 2555665
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.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question