Board index » delphi » Lock and Unlock records

Lock and Unlock records

I need some information how to lock and unlock records of data files in
Borland Pascal for DOS and how can i open files in shared mode.

Thank's

Pedro Sousa
(from Portugal)

P.S. - Sorry my english !

 

Re:Lock and Unlock records


Quote
jcf1 wrote in message <6o1351$85...@news.EUnet.pt>...
>I need some information how to lock and unlock records of data files in
>Borland Pascal for DOS and how can i open files in shared mode.

>Thank's

>Pedro Sousa
>(from Portugal)

>P.S. - Sorry my english !

Look at this

You will have to write the procedures YesNo and OkBox yourselves.

Type
      ShareModes    = (CompMode,DenyAll,DenyWrite,DenyRead,DenyNone);
      AccessModes   = (Read,Write,ReadWrite);

var   IoCode         : Word;

procedure FReset(var Map     : FileRec;
                     RecGr   : word;
                     AccMode : Accessmodes;
                     shmode  : sharemodes);
const
      childprocess=128;

var tel        : byte;
    dummy      : boolean;
    naam       : string;
    Regs       : registers;
    sharemode  : byte;
    accessmode : Byte;

begin
map.recsize:=recgr;
map.mode:=fminout;
IOCode:=0; tel:=0;
case AccMode of
   Read      : Accessmode:=0;
   write     : Accessmode:=1;
   ReadWrite : Accessmode:=2;
end;
case shmode of
   CompMode  : sharemode:=0;
   denyall   : sharemode:=16;
   denywrite : sharemode:=32;
   denyread  : sharemode:=48;
   denynone  : sharemode:=64;
end;
dummy:=true;
while dummy do
  begin
   inc(tel);
   with regs do
    begin
     ah:=$3D;
     al:=childprocess+sharemode+AccessMode;
     ds:=seg(map.name); dx:=ofs(map.name);
     naam:=map.name;
     msdos(regs);
     if flags and fcarry=1 then
      begin
       IOCode:=ax;
       if IOCode=2 then exit;  {file not found}
       if iocode=3 then
                      begin;
                        okbox('Path not found.',mferror);
                        exit;
                      end;
      end else
       begin
        map.handle:=ax;
        IOCode:=0;
        exit;
       end;
    end;
   if tel=30 then
    begin
     if not(Yesno('Network Access Arror.'+#13+
                  'Try Again ?',mfconfirmation)) then
        begin
          iocode:=99;
          exit;
        end;
     tel:=0;
   end;
end;    {einde while}
end;

Example

procedure StoreAsDefaultColors;
var N        : Word;
    Txt      : String[9];
    ColorDef : String;
    Filvar    : File;
    Map    : FileRec Absolute Filvar;
Begin
    ColorDef:=ColorStrg;

    assign(filvar,'Default.klr');
    Freset(map,1,readwrite,denyall);
    if iocode=2 then
      begin
        rewrite(filvar,1);
        close(filvar);
        Freset(map,1,readwrite,denyall);
        Truncate(filvar);
      end;

    ColorStrg:=ColorDef;

    For N:=1 to length(ColorDef) do
       Begin
         Txt:=HexString(ord(colordef[n]));
         txt:='$'+copy(txt,8,2);
         txt:='#'+txt;
         Blockwrite(filvar,txt[1],length(txt));
       End;
    close(filvar);
End;

Re:Lock and Unlock records


Quote
jcf1 wrote: <6o1351$85...@news.EUnet.pt>...
>I need some information how to lock and unlock records of data files
in
>Borland Pascal for DOS and how can i open files in shared mode.

>Thank's

>Pedro Sousa
>(from Portugal)

>P.S. - Sorry my english !

A few years ago I wrote the unit:

===========================cut===============================
unit NetFile;
interface
const
     F_StdOpen           = $02;
     F_ReadOnlyOpen      = $00;
     F_WriteOpen         = $01;
     F_LockInherited     = $80;
     F_Compatibility     = $00;  { Full Access }
     F_FullProtection    = $10;
     F_ReadProtection    = $30;
     F_WriteProtection   = $20;
     F_NoProtection      = $40;
{ Locking }
     F_Lock              = $5C00;
     F_UnLock            = $5C01;
     F_FromStart         = $00000000;
     F_WholeFile         = $FFFFFFFF;
function LockNetFile (var f:file; Mode:integer;
Start,Count:LongInt):Boolean;
procedure SetNetFileMode (Mode:byte);
implementation
function LockNetFile (var f:file; Mode:integer;
Start,Count:LongInt):Boolean;
assembler;
asm
   LES   DI,f
   mov   ax,Mode
   mov   bx,es:[di]
   mov   cx,Start.Word[0]
   mov   dx,Start.Word[2]
   mov   si,Count.Word[0]
   mov   di,Count.Word[2]
   int   21h
   jnc   @@1
   mov   al,False
   jmp   @@2
@@1:
   mov  al,True
@@2:
end;
procedure SetNetFileMode (Mode:byte);
assembler;
asm
   mov al,Mode
   mov FileMode,al
end;
end.
===========================cut===============================

Maybe this will help U.

--------------------------------------------------------------------
Zbigniew Lukaszewicz
z.lukaszew...@torun.tpsa.pl
--------------------------------------------------------------------

Other Threads