Board index » delphi » File sharing/locking in Delphi/Pascal

File sharing/locking in Delphi/Pascal

In article <4esqoo$...@spider.rmplc.co.uk>,
   aing...@rmplc.co.uk (Andy Ingham) wrote:
]-I have written a few network applications for the college where I work
]-but I am having problems with sharing violation errors from windows,
]-which I can't trap with IOResult. I used to write my applications in
]-VB3, which had the "Open <filename> for Input Shared" method of
]-opening files. I know there is something called FileMode, but I don't
]-know the extended modes above 2, or how to use it.
]-
]-Can anyone help? A bit of example code would be nice.
]-
]-Thanks,
]-
]-Andy.
]-
]-

here's a response given to this question sometime earlier.  I've
followed the advice given with good results...

Mark Vaughan

----------------------------------------------------------------------------------

FROM: G...@epix.net (Greg P)
SUBJECT: Re: Filemode= for sharing
DATE: 6 Sep 1995 00:23:44 GMT
ORGANIZATION: MRT

In article <95Sep05135635.andib...@IH.USA.Com>, jgla...@lansoft.com (Jon Glazer) says:

Quote

>I need to open a file in share mode on a Novell Network.  The file in
>question is a text file but I may need to do this using a untyped
>file type.

You'll need to use TP's FileMode.

const {FileMode constants 1 from column A 'and' one from column B}
      fmRO  = $00;  {ReadOnly }     fmDA  = $10;  {DenyAll  }
      fmWO  = $01;  {WriteOnly}     fmDW  = $20;  {DenyWrite}
      fmRW  = $02;  {ReadWrite}     fmDR  = $30;  {DenyRead }
                                    fmDN  = $40;  {DenyNone }

Frinstance, to open a file for Read Only but allow others on the Net to share it:

        FileMode := fmRO + fmDN;  {read only, deny none}

open for Read Only, don't let ANYone else have access:

        FileMode := fmRO + fmDA;

etc.  Hope this helps.

Oh... run this immediate before Reset/Rewrite when you open the file.  
the mode stays unchanged until you use the FileMode procedure again with
different constants.

----------------------------------------------------------------------------------

 

Re:File sharing/locking in Delphi/Pascal


I have written a few network applications for the college where I work
but I am having problems with sharing violation errors from windows,
which I can't trap with IOResult. I used to write my applications in
VB3, which had the "Open <filename> for Input Shared" method of
opening files. I know there is something called FileMode, but I don't
know the extended modes above 2, or how to use it.

Can anyone help? A bit of example code would be nice.

Thanks,

Andy.

Re:File sharing/locking in Delphi/Pascal


Quote
Andy Ingham wrote:
> I have written a few network applications for the college where I work
> but I am having problems with sharing violation errors from windows,
> which I can't trap with IOResult. I used to write my applications in
> VB3, which had the "Open <filename> for Input Shared" method of
> opening files. I know there is something called FileMode, but I don't
> know the extended modes above 2, or how to use it.

I've write ona network application and I also had problems with
file in server which has multiple readers and multiple writers
at same time. Finally I find solution that works:

        1) Open file with fmOpenReadWrite + fmOpenShareDenyNone
        2) Before every read or write operation lock the file
           with int 21h function 5Ch and immediately after read/
           write unlock file with same function.

I tried many different combinations with file openmode flags but
allways there was some kind of problem but this solution has been
working now about a month without any problems.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Ari Hirviniemi, Lappeenranta, Finland (ari.hirvini...@ktieto.fi)
All my opinions and comments are personal and have nothing to do
with my employer.

Other Threads