Loading UTF-8 files

<< Click to display table of contents >>

Loading UTF-8 files

This example shows how to load Unicode UTF-8 file:

procedure LoadUTF8(rv: TCustomRichViewconst FileName: String

  StyleNo, ParaNo: Integer); 

var Stream: TFileStream; 

    s: TRVRawByteString

    ws: TRVUnicodeString

begin 

  Stream := TFileStream.Create(FileName, fmOpenRead); 

  SetLength(s, Stream.Size); 

  Stream.ReadBuffer(PRVAnsiChar(s)^, Stream.Size); 

  Stream.Free; 

  rv.Clear; 

  ws := UTF8Decode(s); 

  rv.AddTextNLW(ws, StyleNo, ParaNo, ParaNo, False); 

end

Call:

LoadUTF8(RichViewEdit1, 'test.txt'00); 

RichViewEdit1.Format

 

See also:

Unicode in TRichView.