trichview.com Forum Index trichview.com
TRichView support forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Example] Loading UTF-8 files

 
Post new topic   Reply to topic    trichview.com Forum Index -> Examples, Demos
View previous topic :: View next topic  
Author Message
Sergey Tkachenko
Site Admin


Joined: 27 Aug 2005
Posts: 6576

PostPosted: Sun Aug 28, 2005 11:40 am    Post subject: [Example] Loading UTF-8 files Reply with quote

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

Code:
procedure LoadUTF8(rv: TCustomRichView; const 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:
Code:
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)

(2008-Dec-9: updated for compatibility with TRichView 11 and Delphi 2009)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    trichview.com Forum Index -> Examples, Demos All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group