The type of Str
does not match the type of result of UTF8Encode
- so the line Str := UTF8Encode
damages data. Instead of Str
you should declare and use variable with a datatype mathcing the one of Utf8Encode
result.
Same is true for Str2 := UTF8Decode(Str)
line with regard to wrong data type of Str
parameter the. It should be replaced with another var of proper datatype.
Str3
is not declared, so the code won't even compile. Add the Str3: WideString;
line.
ShowMessage
does not work with UTF-16, so then you make your own popup function that does.
Make your own dialog containing Tnt
unicode-aware Label to display the text. And your new ShowMessage
-like function would set the label's caption and then display that dialog instead of stock unicode-unaware one.
You may look at http://blog.synopse.info/post/2011/03/05/Open-Source-SynTaskDialog-unit-for-XP%2CVista%2CSeven for exampel of such dialogs, but i don't know if they are UTF-16 aware on D7.
Another option is searching TnT Sources for a ready-made unicode-aware function like ShowMessage - there may be one, or not.
Yet another option is using Win32 API directly, namely the MessageBoxW
function working with PWideChar
variables for texts: see http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505.aspx
@DavidHeffernan MessageBoxW
needs a lot of boilerplate both due to using C-Strings and for giving too much flexibility. It may be considered kinda good replacement for MessageDlg
but not so much for ShowMessage
. Then i am sure that TnT has ShowMessage
conversion and that implementing own dialog would be good for both application look-and-feel and topic-starter experience.
You may also switch from obsolete Delphi 7 to modern CodeTyphon that uses UTF-8 for strings out of the box. You should at very least give it a try.
To read and write WideString
from registry using Delphi 7 RTL you can make two easy options:
- Convert WideString to UTF8 AnsiString and save it via
TRegistry.WriteString
and do back conversion on reading. - Save
WideString
as binary data:Cardinal(Length)
followed byarray of WideChar
usingTRegistry.WriteBinaryData
- You can also use
function RegReadWideString(const RootKey: DelphiHKEY; const Key, Name: string): WideString;
andRegWriteWideString
courtesy of http://jcl.sf.net
Whatever approach you'd choose - you have to do your own class on top of TRegistry that would be uniformly implementing those new TYourNewRegistry.WriteWideString
and TYourNewRegistry.ReadWideString
methods, so that the string written would always be read back using the same method.
However, since you already got TNT installed - then look carefully inside,. there just should be ready-made unicode-aware class like TTntRegistry
or something like that.