Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Resources and 'foreign' characters not showing properly


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Sep 17, 2014 1:08 PM Last Post By: Remy Lebeau (Te...
Mats karlsson

Posts: 64
Registered: 11/8/99
Resources and 'foreign' characters not showing properly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 17, 2014 12:58 PM
Hello,
I'm using c++ builder XE3.

I found the 'Resources and Images' option under 'Project', which is a
great tool to add resources to an application, which I believe one had
to do manually in the past.

Anyway, I have added a text resource, using the RCDATA resource type.
The text resource contain some 'foreign', Swedish characters, and may
later on, contain characters from other languages as well. (The text is
a 'CREDITS' text listing many names)

I read the resource from within the application like this:

//Load from resource
TResourceStream *Stream = new TResourceStream((int)HInstance, "CREDITS", 
RT_RCDATA); //RT_RCDATA is the Resource Type.
 
     __try
     {
         TStringList *sList = new TStringList;
         __try
         {
             sList->LoadFromStream(Stream);
 
             //Open the credits form
             TCreditsForm* credits = new TCreditsForm(NULL);
 
             for(int i = 0; i < sList->Count; i++)
             {
                 String line;
                 line =  sList->Strings[i];
                 credits->creditsMemo->Lines->Add(line);
             }
 
             credits->ShowModal();
 
....


Problem is that the 'foreign' characters in the stream now look funny.

Question is, what is the proper way to get them to show properly on the
memo in the code above?

UPDATE: I managed to find the answer to the question before posting
question.

I post it as a tip for someone else.

The key seem to be to change

sList->LoadFromStream(Stream);


to

sList->LoadFromStream(Stream, TEncoding::UTF8);


After doing so, the characters show ok.
tk

Edited by: totte karlsson on Sep 17, 2014 1:03 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Resources and 'foreign' characters not showing properly  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 17, 2014 1:08 PM   in response to: Mats karlsson in response to: Mats karlsson
totte wrote:

The text resource contain some 'foreign', Swedish characters

In what encoding exactly? ANSI? UTF-8? UTF-16?

and may later on, contain characters from other languages as well.
(The text is a 'CREDITS' text listing many names)

Then you need to make sure you are using UTF-8 or UTF-16 for the data encoding.

I read the resource from within the application like this:

You are loading raw binary data into a TStringList without specifying the
data's encoding. TStringList will look for a BOM, and if not found than
it will assume the OS default Ansi encoding. It sounds like there is no
BOM in your data.

Problem is that the 'foreign' characters in the stream now look funny.

That happens if you load text using the wrong encoding.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02