On Mon, 5 Oct 2020, Ryan Joseph via fpc-pascal wrote:
On Oct 5, 2020, at 3:23 PM, Michael Van Canneyt via fpc-pascal
wrote:
So I think you're looking at 6 or even 8 versions of this hypothetical
function...
Ouch. :)
I'm sure this code already exists in the RTL though, right? I assum
El 6/10/20 a les 9:01, Michael Van Canneyt via fpc-pascal ha escrit:
A simple filecreate, allocate buffer, fileread, fileclose will probably
be easiest.
Lazarus has a ReadFileToString in fileutil.
Bye
--
Luca
___
fpc-pascal maillist - fpc-pascal@
I use this function to read a file into a string:
function ReadFile(const FileName: TFileName): String;
var
InputFile: THandle;
FileSize, BytesRead: Integer;
Buffer: String='';
begin
try
InputFile := FileOpen(FileName, fmOpenRead);
if InputFile = -1 then
begin
WriteLn
Op 2020-10-05 om 20:45 schreef Ryan Joseph via fpc-pascal:
I often need to use a function which reads a file into a string, as is so
common in so many scripting languages. Can it be considered to add something
like this to the RTL? Since we have a refcounted Ansistring type it's natural
for t
On Mon, 5 Oct 2020, Ryan Joseph via fpc-pascal wrote:
On Oct 5, 2020, at 5:08 PM, Jean SUZINEAU via fpc-pascal
wrote:
In my own code I use BlockRead/BlockWrite, but I'm wondering if I've not seen
this somewhere in RTL.
This looks good to me what about the concerns raised by Michael?
> On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal
> wrote:
>
> I added the following functions to the sysutils unit (rev 47056):
Great, thanks Michael.
I've always used AnsiString so why is UnicodeString preferable here?
So is the idea we need to specify an UTF-8 encoding for
Not 100% on this but I think the gist is that UnicodeString is compatible with
AnsiString and a conversion is done on assignment.
--
Alexander Grotewohl
https://dcclost.com
From: fpc-pascal on behalf of Ryan
Joseph via fpc-pascal
Sent: Tuesday, October 6, 2020
Wouldn't it be better to implement it directly as *IOUtils.TFile* (like
Deplhi)?
*class function ReadAllBytes(const Path: string): TBytes; static;class
function ReadAllLines(const Path: string): TStringDynArray;overload;
static;class function ReadAllLines(const Path: string; const Encoding:
TEn
Well, the answer is twofold:
1. IOUtils does not exist yet. Now the OP has a solution.
2. I don't use IOUtils and don't plan to.
Its .NET-like approach has no added value for me.
Just like I don't use rtii unit, but always use the more low-level
typinfo unit.
But once TFile will be im
On Tue, Oct 6, 2020 at 10:12 AM Michael Van Canneyt via fpc-pascal
wrote:
> // Assume TEncoding.SystemEncoding
> Function GetFileAsString(Const aFileName : RawByteString) : RawByteString;
> // Specify encoding
> Function GetFileAsString(Const aFileName : RawByteString; aEncoding :
> TEncoding)
On Tue, 6 Oct 2020, Ryan Joseph via fpc-pascal wrote:
On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal
wrote:
I added the following functions to the sysutils unit (rev 47056):
Great, thanks Michael.
I've always used AnsiString so why is UnicodeString preferable here?
I
On Tue, 6 Oct 2020, Bart via fpc-pascal wrote:
On Tue, Oct 6, 2020 at 10:12 AM Michael Van Canneyt via fpc-pascal
wrote:
// Assume TEncoding.SystemEncoding
Function GetFileAsString(Const aFileName : RawByteString) : RawByteString;
// Specify encoding
Function GetFileAsString(Const aFileNam
I use a secondary unit as alias of all separate units as Marco suggests in
https://github.com/fanoframework/fano/blob/master/src/fano.pas
However I am curious if merging units like this has drawback. AFAIK smart
linking works.
Sent from Yahoo Mail on Android
On Sat, Oct 3, 2020 at 3:31, Marc
> On Oct 6, 2020, at 2:52 PM, Zamrony P. Juhara via fpc-pascal
> wrote:
>
> I use a secondary unit as alias of all separate units as Marco suggests in
>
> https://github.com/fanoframework/fano/blob/master/src/fano.pas
>
> However I am curious if merging units like this has drawback. AFAIK sm
Since we're on the topic how about another one-liner for reading all the files
in directory into a dynamic array? This has the added benefit of getting
enumeration for free. This is standard stuff for working with files in
scripting languages so I think the FPC RTL should include something like
> On Oct 6, 2020, at 1:42 AM, Jer Haan via fpc-pascal
> wrote:
>
> I use this function to read a file into a string:
Not sure how Michael implemented it but we have this in the RTL now, so we can
throw away our ReadFile functions. I have many of those littered around in
various projects so
16 matches
Mail list logo