|
<< Click to display table of contents >> Loading UTF-8 files |
These examples show how to load Unicode UTF-8 file.
procedure LoadUTF8(rv: TCustomRichView; const FileName: String;
StyleNo, ParaNo: Integer);
var Stream: TFileStream;
s: TRVRawByteString;
ws: TRVUnicodeString;
begin
// loading UTF-8 in s
Stream := TFileStream.Create(FileName, fmOpenRead);
SetLength(s, Stream.Size);
Stream.ReadBuffer(PRVAnsiChar(s)^, Stream.Size);
Stream.Free;
rv.Clear;
// converting from s (UTF-8) to ws (UTF-16)
ws := UTF8Decode(s);
// adding ws in document
rv.AddTextNLW(ws, StyleNo, ParaNo, ParaNo, False);
end;
Call:
LoadUTF8(RichViewEdit1, 'test.txt', 0, 0);
RichViewEdit1.Format;
RichViewEdit1.Clear;
RichViewEdit1.LoadText('test.txt', 0, 0, False, CP_UTF8);
RichViewEdit1.Format;
See also: