<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">El 06/10/2020 a las 01:08, Jean
SUZINEAU via fpc-pascal escribió:<br>
</div>
<blockquote type="cite"
cite="mid:b2eeeff1-fec0-6753-4339-b39047dfa96b@wanadoo.fr">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>In my own code I use BlockRead/BlockWrite, but I'm wondering if
I've not seen this somewhere in RTL.<br>
</p>
<p><a moz-do-not-send="true"
href="https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas">https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas</a></p>
</blockquote>
Just nitpicking.<br>
Shouldn't "try" be after the "reset" and after the "rewrite"?<br>
Why don't you allow to write an empty string?<br>
<br>
<blockquote type="cite"
cite="mid:b2eeeff1-fec0-6753-4339-b39047dfa96b@wanadoo.fr">
<pre>function String_from_File( _FileName: String): String;</pre>
<pre>var</pre>
<pre> F: File;</pre>
<pre> Longueur: Integer;</pre>
<pre>begin</pre>
<pre> Result:= '';</pre>
<pre> if not FileExists( _FileName) then exit;</pre>
<pre> AssignFile( F, _FileName);</pre>
<pre> try</pre>
<pre> Reset( F, 1);</pre>
<pre> Longueur:= FileSize( F);</pre>
<pre> if 0 = Longueur then exit;</pre>
<pre> SetLength( Result, Longueur);</pre>
<pre> BlockRead( F, Result[1], Longueur);</pre>
<pre> finally</pre>
<pre> CloseFile( F);</pre>
<pre> end;</pre>
<pre>end;</pre>
<pre>procedure String_to_File( _FileName: String; _S: String);</pre>
<pre>var</pre>
<pre> F: File;</pre>
<pre>begin</pre>
<pre> if '' = _S then exit;</pre>
<pre> AssignFile( F, _FileName);</pre>
<pre> try</pre>
<pre> ReWrite( F, 1);</pre>
<pre> BlockWrite( F, _S[1], Length( _S));</pre>
<pre> finally</pre>
<pre> CloseFile( F);</pre>
<pre> end;</pre>
<pre>end;</pre>
<p><br>
</p>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
fpc-pascal maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a>
</pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Saludos
Santiago A.</pre>
</body>
</html>