[fpc-pascal] Adding file to string to the RTL

Winfried Bartnick winni at bartnick.info
Tue Oct 6 01:48:38 CEST 2020


Am 06.10.20 um 01:08 schrieb Jean SUZINEAU via fpc-pascal:
>
> 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;
>
>
Hi!


Great idea!

Longueur  should be Int64


Winni



>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20201006/0b5701e9/attachment.htm>


More information about the fpc-pascal mailing list