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 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.
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.
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
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).
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
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •