Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Delphi Unicode
Hi, I am trying to show a message box item as "اردو ویکیپیڈیا", this is a unicode character; I am using Delphi 7; but in the editor it is showing as ????? ?????, it is not supporting unicode;
 
Can any one tell me what I need to do in the Delphi editor or project to make it unicode compatible?
code"
MessageBoxW(0,'اردو ویکیپیڈی', 'Print_info',MB_OK);
 
This is showing as
MessageBoxW(0,'?????? ????', 'Print_info',MB_OK);
 
Thanks
Posted 19-Apr-13 8:15am
iDebD842
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I'll tell you the sad story, but some solutions do exist.
 
Unfortunately, this version of Delphi had limited support of Unicode. Borland VCL was not Unicode-enabled at all, so, with the controls you are using, you cannot do anything at all. You would need some custom controls replacing VCL.
 
In 2005, I found a relatively smooth way to derive VCL controls to add Unicode support. I though that rewriting the VCL completely would be infeasible, even though any other way though to be impossible, as far as I could see from Delphi community material. I found a tricky way: I inherited select controls from VCL controls and develop a trick based on Windows API: re-registering of the window class on the fly, adding Unicode support and keeping everything else. This is the idea you could use.
 
I published this work in the printed The Delphi Magazine:
S. A. Kryukov, ‘Unicode Controls: What Can VCL Do?’, The Delphi Magazine, 116 (April 2005), p. 33-43
 
Unfortunately, pretty soon after that this magazine was closed. I wasn't a subscriber of this magazine myself. I don't have a hard copy, only a copy of my original work, before editor's proof. The on-line access to the code was removed with time, but I have it. I used to see some (illegal) copies of the code of this work on the Web. Personally, I would not mind if anyone uses it. And I have a very little incentive to re-print it (even assuming it would be legally fine), as that version of VCL is quite obsolete.
 
So, what else can I advise?
 
First of all, you can use later version of Delphi, starting from Embarcadero Delphi 2009 (Delphi 12, code named Tiburón). This is when full Unicode support for VCL was first introduced: http://en.wikipedia.org/wiki/Embarcadero_Delphi[^].
 
Another good option would be switching to open-source Free Pascal:
http://en.wikipedia.org/wiki/Free_Pascal[^],
http://www.freepascal.org/[^].
 
One great benefit of Free Pascal is that it is truly multi-platform. And it has Delphi compatibility mode. Unicode is of course supported.
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In your case the simplest would be to create UTF8 representation of your string, write ConvertUTF8ToUTF16 function or find an existing one and then call MessageBoxW(0, ConvertUTF8ToUTF16('yourUTF8Constant'), ... ). This way you can deal with any Unicode text in non-Unicode Delphi.
 
Edit: seems that many people don't understand simple shortcuts. The 'yourUTF8Constant' literal value can be created in a unicode text editor, saved to UTF8-encoded text file and either loaded from the file (or you can store the file as a resource) or just be copied to your source code (but in the latter case you need to check that the text is displayed properly and is not spoiled when the source code is opened on the system with another code page being active).
 
UTF8 is in general a more flexible and universal way to deal with unicode in non-unicode environments. For example, in PHP which is not Unicode the approach I described is used all the time to work with Unicode.
 
Of course you need to convert UTF8 to UTF16 when passing Unicode strings to system functions that expect Unicode. You can take conversion functions in ElPack or in TNT library or write your own function.
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 19-Apr-13 13:54pm
   
It won't work at all, because OP would not be able to type Unicode text using non-Unicode version of VCL. You can do anything with the stings, right, but it would not help to solve the problem, much more complex one. Please see my answer for explanations. Sorry, but you are not aware of this problem and are advising something you could not possibly try out, so I had to vote 1.
—SA
Eugene Mayeski at 19-Apr-13 14:03pm
   
Wrong. One can use a unicode editor to get the UTF8 string, then embed the string to the source code.
 
And kudos for telling me about me not knowing the problem, as I wrote ElPack (now LMD ElPack) 15 years ago, and that was true Unicode library for Delphi ;) (which unlike TNT controls delivered the real Unicode solution on Win9x and not hacks around NT functions).
Sergey Alexandrovich Kryukov at 19-Apr-13 16:20pm
   
You did not get it. First, did you pay attention for the VCL version? You did not mention you library in your answer. How can you explain it? Could you provide a reference, if you have any?
 
Yes, real Unicode solution was possible and it does exist, for, example, as later version of VCL, but this is possible only with re-writing the library from scratch, writing a new one, or modifying VCL based on it source code, which was actually done in later versions of Delphi.
 
—SA
Eugene Mayeski at 20-Apr-13 2:13am
   
Please see LMD ElPack. At times when I added Unicode to it, it provided Unicode support for Delphi 3 to Delphi 7 (there was no newer versions of Delphi in 2001-2003) on Win9x. Now tell me that I don't get it.
Sergey Alexandrovich Kryukov at 20-Apr-13 20:21pm
   
I might got it, but you never mentioned it or anything else which could work in your answer. I wonder why?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 330
1 BillWoodruff 260
2 Sergey Alexandrovich Kryukov 240
3 OriginalGriff 216
4 Afzaal Ahmad Zeeshan 208
0 OriginalGriff 6,168
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,028
3 Manas Bhardwaj 4,539
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 20 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100