[Lazarus] TFileStream

Paul Ishenin ip at kmiac.ru
Thu Jan 29 10:27:28 CET 2009


Dave Coventry wrote:
...
>        FS:=TFileStream.Create(fname, fmshareDenyWrite);
...
> I am trying to read a block of 4 bytes, increment it by one and write
> it back again.
> 
> However, if fails on the write.

Please read carefully what have you written:

FS := TFileStream.Create(fname, fmShareDenyWrite);

you passed only fmShareDenyWrite but you have not told to the file 
stream that you want to write :)

There are few modes in which you can open your stream:

   fmCreate        = $FFFF;
   fmOpenRead      = 0;
   fmOpenWrite     = 1;
   fmOpenReadWrite = 2;

You had not passed any of them => you passed 0 = fmOpenRead. As result 
you can only read.

If you want to read and write then pass fmOpenReadWrite as mode:

FS := TFileStream.Create(fname, fmOpenReadWrite or fmShareDenyWrite);

Best regards,
Paul Ishenin.




More information about the Lazarus mailing list