Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Indirizzi - IoFile.pas

IoFile.pas

Caricato da: Poggi Marco
Scarica il programma completo

  1. unit IoFile;
  2.  
  3. { unita per gestire i file binari }
  4.  
  5. interface
  6. uses Nominativo;
  7.  
  8. type tpersone=indirizzo;
  9.      qword=Int64;
  10.  
  11. type fiolima=object
  12.  private
  13.   fp:file of indirizzo;
  14.   nome:tstr;
  15.   modalita:char;
  16.  public
  17.   function ApriFile(fr:tstr; m:char):boolean;
  18.   function NumeroDiCampi:qword;
  19.   function FineFile:boolean;
  20.   procedure scrivi(rec:tpersone);overload;
  21.   procedure scrivi(rec:tpersone; pos:qword);overload;
  22.   function leggi:tpersone;overload;
  23.   function leggi(pos:qword):tpersone;overload;
  24.   function GetNome:string;
  25.   procedure ChiudiFile;
  26. end;
  27.  
  28. function GetCartella:string;
  29. function FileEsistente(nome:string):boolean;
  30.  
  31. implementation
  32.  
  33. function fiolima.ApriFile(fr:tstr; m:char):boolean;
  34. var ch:boolean;
  35. begin
  36.  nome:=fr;
  37.  modalita:=UpCase(m);
  38.  AssignFile(fp, fr);
  39.  case modalita of
  40.    'W': begin
  41.          {$I-}
  42.            Rewrite(fp);
  43.          {$I+}
  44.          ch:=IoResult=0;
  45.         end;
  46.     'R': begin
  47.          {$I-}
  48.           Reset(fp);
  49.          {$I+}
  50.          ch:=IoResult=0;
  51.          if ch then seek(fp, 0);
  52.         end;
  53.      'A': begin
  54.          {$I-}
  55.           reset(fp);
  56.          {$I+}
  57.          if IoResult=0 then
  58.          begin
  59.           seek(fp, FileSize(fp));
  60.           ch:=true;
  61.          end
  62.          else
  63.          begin
  64.            {$I-}
  65.               Rewrite(fp);
  66.            {$I+}
  67.             ch:=IoResult=0;
  68.          end;
  69.         end;
  70.     else ch:=false;
  71.  end;
  72.  ApriFile:=ch;
  73. end;
  74.  
  75. function fiolima.NumeroDiCampi:qword;
  76. begin
  77.  if (modalita='W') or (modalita='R') or (modalita='A') then NumeroDiCampi:=FileSize(fp)
  78.  else NumeroDiCampi:=0;
  79. end;
  80.  
  81. function fiolima.FineFile:boolean;
  82. var ch:boolean;
  83. begin
  84.  if (modalita='W') or (modalita='R') or (modalita='A') then ch:=EOF(fp)
  85.  else ch:=false;
  86.  FineFile:=ch;
  87. end;
  88.  
  89. procedure fiolima.scrivi(rec:tpersone); // overload;
  90. begin
  91.  if (modalita='W') or (modalita='R') or (modalita='A') then write(fp, rec);
  92. end;
  93.  
  94. procedure fiolima.scrivi(rec:tpersone; pos:qword); // overload;
  95. begin
  96.  if (modalita='W') or (modalita='R') or (modalita='A') then
  97.  begin
  98.   seek(fp, pos);
  99.   write(fp, rec);
  100.  end;
  101. end;
  102.  
  103. function fiolima.leggi:tpersone; // overload;
  104. var rec:tpersone;
  105. begin
  106.  if ((modalita='W') or (modalita='R') or (modalita='A')) and (not eof(fp)) then
  107.    read(fp, rec);
  108.  leggi:=rec;
  109. end;
  110.  
  111. function fiolima.leggi(pos:qword):tpersone; // overload;
  112. var rec:tpersone;
  113. begin
  114.  if (modalita='W') or (modalita='R') or (modalita='A') then
  115.  begin
  116.   seek(fp, pos);
  117.   read(fp, rec);
  118.  end;
  119.  leggi:=rec;
  120. end;
  121.  
  122. function fiolima.GetNome:string;
  123. begin
  124.  GetNome:=nome;
  125. end;
  126.  
  127. procedure fiolima.ChiudiFile;
  128. begin
  129.   if (modalita='W') or (modalita='R') or (modalita='A') then
  130.   begin
  131.    // Flush(fp);
  132.    seek(fp, 0);
  133.    CloseFile(fp);
  134.   end;
  135.   modalita:='C';
  136. end;
  137.  
  138. function GetCartella:string;
  139. var cartella:string;
  140. begin
  141.  GetDir(0, cartella);
  142.  GetCartella:=cartella;
  143. end;
  144.  
  145. function FileEsistente(nome:string):boolean;
  146. var f:text;
  147.     ch:boolean;
  148. begin
  149.  assign(f, nome);
  150.  {$I-}
  151.   reset(f);
  152.  {$I+}
  153.  ch:=IoResult=0;
  154.  if ch then close(f);
  155.  FileEsistente:=ch;
  156. end;
  157.  
  158. begin
  159.  
  160. end.