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

Ryan Joseph genericptr at gmail.com
Mon Oct 5 20:45:19 CEST 2020


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 this to be a one-liner. Not saying we should use TStringList but that's the closest thing I found in the RTL.

function ReadFile(path: Ansistring): Ansistring;
var
  list: TStringList;
begin
  list := TStringList.Create;
  list.LoadFromFile(ExpandFileName(path));
  result := list.Text;
  list.Free;
end;

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list