Assigning a file

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Assigning a file

L505
Does assigning and then reseting a file require write permissions on Linux and Windows? I'm
getting ELnOutError access Denied when I try to assign a file. It works fine if I give the
file write permissions

program Project1;
{$mode objfpc}{$H+}
uses
  SysUtils;
var
  FileName: string;
  TheFile: file of char;
begin
  FileName:= 'test.txt' ;   //a read only file in the directory
  assign(TheFile, filename);
  reset(TheFile);
  readln;
end.


An unhandled exception occurred at $0805B42D : EInOutError : Access denied $0805B42D
$0804DCDE $0804842C

--
L505
http://z505.com

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Assigning a file

Michalis Kamburelis
L505 wrote:

> Does assigning and then reseting a file require write permissions on Linux and Windows? I'm
> getting ELnOutError access Denied when I try to assign a file. It works fine if I give the
> file write permissions
>
> program Project1;
> {$mode objfpc}{$H+}
> uses
>   SysUtils;
> var
>   FileName: string;
>   TheFile: file of char;
> begin
>   FileName:= 'test.txt' ;   //a read only file in the directory
>   assign(TheFile, filename);
>   reset(TheFile);
>   readln;
> end.
>
>
> An unhandled exception occurred at $0805B42D : EInOutError : Access denied $0805B42D
> $0804DCDE $0804842C
>

Do
   FileMode := fmOpenRead;
if you want read-only access. Default FileMode is fmOpenReadWrite, as
far as I remember.

Michalis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Assigning a file

L505

> > An unhandled exception occurred at $0805B42D : EInOutError : Access denied $0805B42D
> > $0804DCDE $0804842C
> >
>
>    FileMode := fmOpenRead;
> if you want read-only access. Default FileMode is fmOpenReadWrite, as
> far as I remember.
>
> Michalis


Thank you. As it states in the documentation, reset depends on filemode!  
Now I know to set it beforehand :)

--
L505
http://z505.com
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal