[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Chinese and Delphi

Posted on 2006-04-03
18
Medium Priority
?
2,194 Views
Last Modified: 2008-01-09
Hi there,
I have created a basic wordprocessor using Delphi. At present everything is in English.
I would like to know how I could make my program accessible to people who speak chinese.
For example I use richedit and edit boxes - how can I allow chinese characters to be types into these controls.
Is it possible?

kind regards
Myles
0
Comment
Question by:myleseven
  • 7
  • 5
  • 3
  • +2
18 Comments
 
LVL 6

Expert Comment

by:saravananvg
ID: 16367907
Hello Sir,

  You could check the following site if it is of any use to you.

http://delphi.about.com/library/weekly/aa102400b.htm

with regards,
padmaja.
0
 
LVL 12

Expert Comment

by:AmigoJack
ID: 16368215
you could use these components http://www.tntware.com/delphicontrols/unicode/downloads.htm - they give you every standard control (also richedit and edit) with unicode (widestring) instead of string support. this way you can display any language of the world
0
 
LVL 9

Expert Comment

by:bernani
ID: 16376183
I use the compos from tnt and they're working very nice

here is a sample code (excerpt) adding ideograms to a listbox. A click on the listbox insert the ideogram in the richedit. You need a Unicode font installed on the system (Arial Unicode MS, SimSun, ...)

procedure TCnEditor.BtCnClick(Sender: TObject);
{LMDLB is a ListBox}
var
i: integer;
begin
LMDLB.clear;
LMDLB.items.BeginUpdate;
{1ère série: 4E de 00 à FF}
LMDLB.Items.Add(WideChar($4E00)); // the first ideo
LMDLB.Items.Add(WideChar($4E01));
LMDLB.Items.Add(WideChar($4E02));
LMDLB.Items.Add(WideChar($4E03));
LMDLB.Items.Add(WideChar($4E04));
LMDLB.Items.Add(WideChar($4E05));
LMDLB.Items.Add(WideChar($4E06));
LMDLB.Items.Add(WideChar($4E07));
LMDLB.Items.Add(WideChar($4E08));
LMDLB.Items.Add(WideChar($4E09));
LMDLB.Items.Add(WideChar($4E0A));
LMDLB.Items.Add(WideChar($4E0B));
LMDLB.Items.Add(WideChar($4E0C));
LMDLB.Items.Add(WideChar($4E0D));
LMDLB.Items.Add(WideChar($4E0E));
LMDLB.Items.Add(WideChar($4E0F));

LMDLB.Items.Add(WideChar($4E10)); //
LMDLB.Items.Add(WideChar($4E11));
LMDLB.Items.Add(WideChar($4E12));
LMDLB.Items.Add(WideChar($4E13));
LMDLB.Items.Add(WideChar($4E14));
LMDLB.Items.Add(WideChar($4E15));
LMDLB.Items.Add(WideChar($4E16));
LMDLB.Items.Add(WideChar($4E17));
LMDLB.Items.Add(WideChar($4E18));
LMDLB.Items.Add(WideChar($4E19));
LMDLB.Items.Add(WideChar($4E1A));
LMDLB.Items.Add(WideChar($4E1B));
LMDLB.Items.Add(WideChar($4E1C));
LMDLB.Items.Add(WideChar($4E1D));
LMDLB.Items.Add(WideChar($4E1E));
LMDLB.Items.Add(WideChar($4E1F));
{and so on .... or use a loop to add a range of ideograms}
LMDLB.items.EndUpdate;
end;

procedure TCnEditor.LMDLBClick(Sender: TObject);
var
i : Integer;
begin
i:= LMDLB.ItemIndex;
tntRichedit1.clear;
tntRichedit1.lines.add(LMDLB.Items[i]);
end;

If you want to change the active keyboard, do this:

procedure TCnEditorArabicKeyboard1Click(Sender: TObject);
beg
//you can change the keyboard layout using the LoadKeyboardLayout API,
//input to chinese
richedit1.setfocus;
LoadKeyboardLayout('00000404',KLF_ACTIVATE); {404 - Traditional chinese - american keyboard}
//input to english
//LoadKeyboardLayout('00000409',KLF_ACTIVATE);
//
//to see the available languages layout look in the regedit in this key [XP]
//
//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout\DosKeybCodes
end;

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:myleseven
ID: 16378172
Hi team,
Thanks for your help. The guys from TNT look very helpful.
I have installed the components onto my Delphi and have ahd a quick play around. No luck in getting them working yet but I think it is a matter of time.
Quick question should TCnEditorArabicKeyboard1Click be TCnEditor.ArabicKeyboard1Click where ArabicKeyboard1 is a buttton?
if so when I click this button should Richedit1 then type with chinese characters?
I don't appear to have 00000404' in my registry, for now could you guys help me to get it working with spanish?

padmaja thanks for your help but I think this only applies to enterprise as I have Delphi 7 pro and could not find the ITE

thanks again
Myles

0
 
LVL 12

Expert Comment

by:AmigoJack
ID: 16384632
create a new project, add a TntMemo, add a button, doubleclick the button and insert the following code:

TntMemo1.Lines.Add(WideChar($4E00)); // the first ideo
TntMemo1.Lines.Add(WideChar($4E01));
TntMemo1.Lines.Add(WideChar($4E02));
TntMemo1.Lines.Add(WideChar($4E03));
TntMemo1.Lines.Add(WideChar($4E04));
TntMemo1.Lines.Add(WideChar($4E05));
TntMemo1.Lines.Add(WideChar($4E06));
TntMemo1.Lines.Add(WideChar($4E07));
TntMemo1.Lines.Add(WideChar($4E08));
TntMemo1.Lines.Add(WideChar($4E09));
TntMemo1.Lines.Add(WideChar($4E0A));
TntMemo1.Lines.Add(WideChar($4E0B));
TntMemo1.Lines.Add(WideChar($4E0C));
TntMemo1.Lines.Add(WideChar($4E0D));
TntMemo1.Lines.Add(WideChar($4E0E));
TntMemo1.Lines.Add(WideChar($4E0F));

thats the demo :) you probably dont "get it working" because the delphi code editor itself cant handle unicode. the most simple demo is also to start this project, then open your internet browser, watch some chinese website, copy any text and then paste it to the memo. then you see that it is able to display the japanese characters.


to get this all working your windows version must support unicode. that are NT4, 2000, XP, 2003 - simply use "Tahoma" as font for your components
0
 

Author Comment

by:myleseven
ID: 16388821
thanks for your guidence,
The main reason that I did not have it installed was because I needed to install chinese onto my op sys.
That LoadKeyboardLayout function is great though and has really got me started.
Now say I need to show chinese characters in a label. How would I go about doing that?

regards
Myles
0
 
LVL 12

Expert Comment

by:AmigoJack
ID: 16407038
like i stated above. you can copy chinese characters from a chinese website and paste them into the "caption" property of a TTntLabel in the property inspector. you had to install chinese on your os? all you need should be having asian/unicode-fonts installed. they may suck up to 260MB but then tahoma.ttf and others are able to display a lot of unicode characters.
0
 
LVL 9

Accepted Solution

by:
bernani earned 500 total points
ID: 16411112
from my previous sample

//This is the onclick event of a button called ArabicKeyboard1
// I change here to Chinese

procedure TCnEditorChineseKeyboard1Click(Sender: TObject);
begin
//You can change the keyboard layout using the LoadKeyboardLayout API,
//input to chinese
//first, gives the focus to tntRichedit
richedit1.setfocus;
//the next line change from your current keyboard layout (english - 00000409) to the Traditional chinese keyboard (404 - Traditional chinese - american keyboard).
//It's an IME - Input Method Editor - with american keyboard layout that let you input a sentence in pinyin (chinese in latin characters).
// You can type the pinyin sentence "wo zai xie Hanzi ne" (I'm writing chinese characters) as you usually do in english and it will be converted to the chinese sentence: 我在写汉字呢 (don't know if the 6 last ideo will be displayed on EE).
//The IME will convert each pinyin syllabe to the correspondant chinese ideo.
LoadKeyboardLayout('00000404',KLF_ACTIVATE); {404 - Traditional chinese - american keyboard}
//input to english
// the next line put your keyboard back to the english keyboard layout
//LoadKeyboardLayout('00000409',KLF_ACTIVATE);
//
//to see the available languages layout look in the regedit in this key [XP]
//
//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout\DosKeybCodes
end;

But for all those to work, you need to have installed the necessary langagues when you installed your XP version. By default, it's not installed.

Here are useful links showing you how to proceed
http://www.newconcept.com/Reference/how_input_chinese.html
http://en.wikipedia.org/wiki/Chinese_input_methods_for_computers
http://en.wikipedia.org/wiki/Chinese_language

.... if so when I click this button should Richedit1 then type with chinese characters?
when you click this button, you change the keyboard layout. It switches from english to chinese
when the chinese keyboard layout is loaded, you can begin to type chinese (using pinyin or the method you prefer)
I gave you the code to load the first chinese characters of the Arial Unicode MS. If you clik on an item in the listbox, the correpondent chinese character will be inserted in the richedit.

.... I don't appear to have 00000404' in my registry
chinese seems not to be installed on your system.

Hope this could help
 
0
 
LVL 9

Expert Comment

by:bernani
ID: 16411119
.... and it will be converted to the chinese sentence: 我在写汉字呢 (don't know if the 6 last ideo will be displayed on EE).

As you can see, the answer is no.

You can paste the line (我在写汉字&#21602) in your Html-Editor to see the chinese characters (save your html page in Big5).
0
 

Author Comment

by:myleseven
ID: 16414107
Thanks alot guys,
I think I have got all of the above, you did answer my last question:
"Now say I need to show chinese characters in a label. How would I go about doing that?"

to some degree as you mentioned I can copy and paste chinese characters into the caption of the label.
Imagine I have over 100 specific labels in my application. These labels will help the user Identify screens and buttons etc.
Is this copy and paste method the only way I can change the caption of a label or a button?
Is there anyway that I can write chinese characters inside  a unit

eg tntlabel1.caption := '你好吗';

xie xie
(thank you)

:)
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 16420598
something like:

unit ChineseResources;

const
  sFileOpen = '你好吗';
  sFileClose = '你好吗#20320;好吗';

so you can have

uses
  ChineseResources;

TnTLabel1.Caption := sFileOpen;

next time, when you want to switch to another language, you can have

unit EnglishResources;

const
  sFileOpen = '&Open';
  sFileClose = '&Close';

and you do not need to modify your code.



DragonSlayer.
0
 

Author Comment

by:myleseven
ID: 16422998
Thanks for the advice DragonSlayer,
Your method to build a program for ease of language switching is a good one and I think I will use it. However when I tried your suggestion I only ended up with the numbers above being displayed in the caption.

I am wondering is there a way (similar to windows) that I can write chinese characters directly into a Delphi unit.
ie my code would look like:

const
  sFileOpen = '你好吗';

xie xie ;)
谢谢你
0
 

Author Comment

by:myleseven
ID: 16423004
interesting
in the above message I just wrote to you I copied and pasted chinese characters into the editor yet they still got displayed as numbers....
0
 

Author Comment

by:myleseven
ID: 16423017
I just tried to copy and paste chinese characters into the IDE and I got a series of ? ? ? where the characters should be. So perhaps there is not a way? Or is it possible to install the chinese language into Delphi 7 profesional
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 16424299
Oops, didn't know that you would take it literally. I was just showing an example on how you can localise it.

An alternative is to use resource files (string tables) as shown here http://delphi.about.com/library/weekly/aa011805a.htm

Type in the string using a Unicode-enabled editor and then compile the resource. And modify the code as in this link http://www.multilizer.com/dev/article.asp?a=583 to make it work for Unicode.


Cheers,
DragonSlayer.
0
 
LVL 9

Expert Comment

by:bernani
ID: 16430586
If you use the tnt compo, you can directly input the chinese char in the text properties (caption, .... ) of the compos.

See the code beneath: I put 2 tntLabels on the form and in the caption of each form I type in chinese character:
- the sentence : ni hao ma
- the word: xiexie
without changing the least other properties of the labels except the font size (from 8 to 20). To achieve this you only toggle your language bar to chinese, type the desired word or sentence in the IME Editor and toggle back to english when you're done.
The code beneath compile OK with D5 on Windows XP Pro with asian languages installed.And D5 isn't unicode.

See in the DFM how the unicode text of the two tntlabeln.caption are stored by Delphi:

 Caption = '???'
    ...
    ...
    ...
    ...
    ...
    ...
    Caption_UTF7 = '+T2BZfVQX' {for the sentence ni hao ma}

___________________________
unit Unit1; {unit1.pas}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, TntStdCtrls;

type
  TForm1 = class(TForm)
    TntLabel1: TTntLabel;
    TntLabel2: TTntLabel;
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

end.

______________________________
{unit1.dfm}

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 214
  Height = 153
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object TntLabel1: TTntLabel
    Left = 32
    Top = 24
    Width = 57
    Height = 24
    Caption = '???'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -20
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
    Caption_UTF7 = '+T2BZfVQX'
  end
  object TntLabel2: TTntLabel
    Left = 32
    Top = 64
    Width = 38
    Height = 24
    Caption = '??'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -20
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
    Caption_UTF7 = '+jCKMIg'
  end
end

0
 
LVL 9

Expert Comment

by:bernani
ID: 16430832
And if I add a tntMemo1 on the form with the words:
ni hao ma
zhongguo ren
hanyu

the dfm is the following:

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 356
  Height = 244
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object TntLabel1: TTntLabel
    Left = 32
    Top = 24
    Width = 57
    Height = 24
    Caption = '???'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -20
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
    Caption_UTF7 = '+T2BZfVQX'
  end
  object TntLabel2: TTntLabel
    Left = 32
    Top = 64
    Width = 38
    Height = 24
    Caption = '??'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -20
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentFont = False
    Caption_UTF7 = '+jCKMIg'
  end
  object TntMemo1: TTntMemo
    Left = 136
    Top = 32
    Width = 185
    Height = 145
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -33
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    Lines.WideStrings = (
      '???'
      '???'
      '??'
      '')
    Lines.WideStrings_UTF7 = (
      '+T2BZfVQX'
      '+Ti1W/U66'
      '+bEmL7Q'
      '')
    ParentFont = False
    TabOrder = 0
  end
end

Note that you don't need to install chinese for Delphi. It's your OS (Windows XP) wich must be able to manage asian languages and provide you the necessary keyboards and editors for input. Windows provide in the installation pack all the required tools for japanese, chinese and korean. You also can extend the service of those languages to all programs. If you do so, you can even type chinese in the standard Notepad.

If you past chinese chars in the Delphi 7 IDE and you receive the ???? result, it probably means that the required language (chinese) insn't installed on your system or that you don't use Unicode aware compo: in the standard Label of Delphi 5, for example, you can't paste chinese chars. If you do so, you'll get the ????? result. Use the tntCompo instead and all is OK


0
 

Author Comment

by:myleseven
ID: 16558827
Sorry I forgot to give points for this one.
Thaks for everyones help
Bernani the points are yours
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question