General TRichView support forum. Please post your questions here
-
standay
- Posts: 272
- Joined: Fri Jun 18, 2021 3:07 pm
Post
by standay »
What is the simplest way to load a file with specific encoding? On most editor components I use I can do it this way:
Code: Select all
memo.Lines.LoadFromFile('test.txt',TEncoding.UTF8);
What I did with the SRichView was this:
Code: Select all
ms := TStringStream.Create('', TEncoding.UTF8);
ms.LoadFromFile(FileName);
ms.Position := 0;
SRichViewEdit1.ActiveEditor.InsertText( ms.DataString );
ms.Free;
That works but is there some easier way I'm missing?
Also, is there a way to make opening and saving text files as UTF8 default?
Thanks!
-
Sergey Tkachenko
- Site Admin
- Posts: 17520
- Joined: Sat Aug 27, 2005 10:28 am
-
Contact:
Post
by Sergey Tkachenko »
The simplest way is to specify 65001 in the CodePage parameter of the text loading methods.
Loading:
Code: Select all
RichViewEdit1.Clear;
RichViewEdit1.LoadText(FileName, 0, 0, False, 65001);
RichViewEdit1.Format;
Inserting at the caret position:
Code: Select all
RichViewEdit1.InsertTextFromFileUTF8(FileName);
or
Code: Select all
RichViewEdit1.InsertTextFromFile(FileName, 65001);
-
standay
- Posts: 272
- Joined: Fri Jun 18, 2021 3:07 pm
Post
by standay »
Thanks Sergey, I'll give this a try later today.
Yes, all these worked, thanks. Also used:
Code: Select all
SRichViewEdit1.ActiveEditor.InsertTextFromFile(FileName, TEncoding.UTF8.CodePage);
Which works too.