File Access Denied error

Posted on 2000-02-22
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)?);
if (reply='y') or (reply='Y')
   Newrec.TranNo:= Newrec.TranNo+1;
   write(Inco,Newrec);<-'file access denied' error flagged here
 writeln('do you wish to continue?(Y/N)');
until (reply='n') or (reply='N');

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

if not eof(InCo)

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.

Question by:chrisbee
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
LVL 12

Accepted Solution

Hypo earned 100 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;

 if not EOF(InCo) then Read (InCo,NewRec);

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
LVL 48

Expert Comment

ID: 2549423
Presumably you have something like

  DataRecord = record
    TranNo : integer;
    InDel : boolean

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

assign(Inco, 'FILENAME');

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)?);
      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)');
until (reply='n') or (reply='N');

Author Comment

ID: 2555665

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.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
qrdesign delphi 5 pdf 5 476
TEdit.SetFocus trouble 3 174
Get notified when a TPopupMenu closes? 4 178
delphi custom sort exception 6 181
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

752 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