Do not use AssignFile. This is legacy code, and it does not work with UnicodeStrings. Instead, use a TStringList or TFileStream to read the file.
[unverified]
procedure ReadFile; var vFileReader : TstringList; begin vFileReader := TStringList.Create; try vFileReader.LoadFromFile('nomes_tst_0001.txt'); mmEntrada.Lines.Assign(vFileReader); finally vFileReader.Free; end; end;
EDITED
Another nice solution is the following function, which I wrote a long time ago:
[test]
function GetFileAsString(aFileName: string; aOffSet : Integer = 0; aChunkSize: Integer = -1): string; var vStream: TFileStream; vBuffer: TBytes; vCurEncoding, vDefEncoding: TEncoding; vOffSet: Integer; vFileSize: Int64; begin vCurEncoding := nil; vDefEncoding := TEncoding.Default; vStream := TFileStream.Create(aFileName, fmOpenRead + fmShareDenyNone); try if aChunkSize > 0 then begin vFileSize := aChunkSize; end else begin vFileSize := vStream.Size; end; vStream.Position := aOffSet; SetLength(vBuffer, vFileSize); vStream.ReadBuffer(Pointer(vBuffer)^, vFileSize); vOffSet := TEncoding.GetBufferEncoding(vBuffer, vCurEncoding); if (vCurEncoding <> vDefEncoding) then begin vBuffer := TEncoding.Convert(vCurEncoding, vDefEncoding, vBuffer, vOffSet, vFileSize - vOffSet); end; Result := vDefEncoding.GetString(vBuffer); finally vStream.Free; end; end;
This function is capable of processing Unicode strings (using the specification), as well as anshing. In fact, it can read all the text files that you have.
source share