Changeset 493 for Common/UCommon.pas


Ignore:
Timestamp:
Dec 10, 2016, 10:59:59 PM (8 years ago)
Author:
chronos
Message:
  • Added: Function to load file content to string.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/UCommon.pas

    r492 r493  
    7070function GetDirCount(Dir: string): Integer;
    7171function MergeArray(A, B: array of string): TArrayOfString;
     72function LoadFileToStr(const FileName: TFileName): AnsiString;
    7273
    7374
     
    492493end;
    493494
     495function LoadFileToStr(const FileName: TFileName): AnsiString;
     496var
     497  FileStream: TFileStream;
     498  Read: Integer;
     499begin
     500  Result := '';
     501  FileStream := TFileStream.Create(FileName, fmOpenRead);
     502  try
     503    if FileStream.Size > 0 then begin
     504      SetLength(Result, FileStream.Size);
     505      Read := FileStream.Read(Pointer(Result)^, FileStream.Size);
     506      SetLength(Result, Read);
     507    end;
     508  finally
     509    FileStream.Free;
     510  end;
     511end;
     512
    494513
    495514
Note: See TracChangeset for help on using the changeset viewer.