In my own code I use BlockRead/BlockWrite, but I'm wondering if I've not seen this somewhere in RTL.

https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas

function String_from_File( _FileName: String): String;
var
   F: File;
   Longueur: Integer;
begin
     Result:= '';
     if not FileExists( _FileName) then exit;
     AssignFile( F, _FileName);
     try
        Reset( F, 1);
        Longueur:= FileSize( F);
        if 0 = Longueur then exit;
        SetLength( Result, Longueur);
        BlockRead( F, Result[1], Longueur);
     finally
            CloseFile( F);
            end;
end;
procedure String_to_File( _FileName: String; _S: String);
var
   F: File;
begin
     if '' = _S then exit;
     AssignFile( F, _FileName);
     try
        ReWrite( F, 1);
        BlockWrite( F, _S[1], Length( _S));
     finally
            CloseFile( F);
            end;
end;


    



_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to