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

Michael Van Canneyt michael at freepascal.org
Thu Oct 8 23:01:32 CEST 2020



On Thu, 8 Oct 2020, Ryan Joseph via fpc-pascal wrote:

>
>
>> On Oct 6, 2020, at 2:12 AM, Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>> 
>> // Read raw content as bytes
>> 
>> Function GetFileContents(Const aFileName : RawByteString) : TBytes;
>> Function GetFileContents(Const aFileName : UnicodeString) : TBytes;
>> Function GetFileContents(Const aHandle : THandle) : TBytes;
>> 
>> // Read content as string
>> 
>> // Assume TEncoding.SystemEncoding
>> Function GetFileAsString(Const aFileName : RawByteString) : RawByteString;
>> // Specify encoding
>> Function GetFileAsString(Const aFileName : RawByteString; aEncoding : TEncoding) : RawByteString;
>> // Assume TEncoding.Unicode contents
>> Function GetFileAsString(Const aFileName : UnicodeString) : UnicodeString;
>> // Specify encoding, return Unicode string.
>> Function GetFileAsString(Const aFileName : UnicodeString; aEncoding : TEncoding) : UnicodeString;
>
> Michael,  Is it possible to extend this same set of functions to writing? 
> Naturally I need to write back to the file now and the same problem
> presents itself.  I have to search through other code bases to find a
> function or Google and find
> https://wiki.freepascal.org/File_Handling_In_Pascal which offers a whole
> host of options.  SaveStringToFile from the wiki link wraps TFileStream
> but having a single low-level function would be best.

Should be easy enough.

Michael.


More information about the fpc-pascal mailing list