trichview.com

trichview.support.examples




Example: Loading UTF-8 files


Return to index


Author

Message

Sergey Tkachenko

Posted: 05/06/2005 23:49:23


Very simple example - how to load Unicode UTF-8 file:


procedure LoadUTF8(rv: TCustomRichView; const FileName: String;

  StyleNo, ParaNo: Integer);

var Stream: TFileStream;

    s: String;

    ws: WideString;

begin

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

  SetLength(s, Stream.Size);

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

  Stream.Free;

  rv.Clear;

  ws := UTF8Decode(s);

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

end;


Call:


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

RichViewEdit1.Format;


(If the StyleNo-th style has Unicode property = True, the file will be

loaded as it is. If not, it will be converted to ANSI text)





Powered by ABC Amber Outlook Express Converter