Programming and use of Chinese character input method under Delphi

zhaozj2021-02-17  97

In the Chinese and Western Document Interfaces of many Windows applications, the entry of Chinese and Western needs to repeat the Chinese character input method, so it is very troublesome, here to introduce a relatively simple solution. The programming environment of this article is Delphi Client / Server Suit Ver 3.0 (hereinafter referred to as Delphi 3.0) and Chinese Windows 95.

1. IMename, IMEMode property under Delphi

In Delphi 3.0 Tedit, TMEMO, Tmaskedit, etc. Initial components are often used in applications, and these three components have IMename, IMEMODE properties. Where the iMename property is the input method name, the corresponding pull-down combo box including all Chinese characters input method in the object viewer; IMEMode property is input mode, and the object viewer also corresponds to a pull-down combo box, in the combo box Includes IMCLOSE, Imopen, Imchinese, IMDontcare, IMSALPHA, IMALPHA six items.

imclose indicates that the input method is in turn off;

Imopen means that the input method is open;

Imchinese means in Chinese input method;

IMDontcare indicates that if the input method is in a closed state, open the most recent input method;

IMSAlPha indicates that the input is in a half-angle;

IMalpha indicates that the input is in full shape.

2. Programming of Chinese character input method under Delphi

In Delphi 3.0, the input elements involved in the Chinese and Western Document Interface have IMENAME, IMEMODE properties. When designing an interface form, the two properties of each component are assigned, the system can automatically turn the set Chinese character input method when the component gets focus. But for the user, this programming method is not a little flexibility. If the input method set by the system is not the user's favorite, then you only reselect again through the input method selector of Windows 95. In fact, this problem can be solved flexibly by placing a label and a pull-down combo box under Form. The form of this example is placed four Label, two Edit, a ComboBox, a MEMO, and a Button below for a description of this example.

(1) Select the File | New Application menu item in Delphi Generate a new application, set the properties of the new form FORM1:

CAPTION = input method programming example;

(2) Add tags Label1, Label2, Label3, and edit box Edit1, Edit2, Memo1 to set its properties:

Label1.caption = Chinese input edit box

Label1.font.size = 12

Label2.caption = Western input edit box

Label2.font.size = 12

Label3.caption = Chinese multi-line text editor

Label3.font.size = 12

Edit1.imemode = Imopen

Edit2.imemode = IMDontcare (default)

Memo1.imemode = imopen

When programming, it is generally set to the IMEMode property of the IMEMode property of Western or Western. The IMEMode property of the input Chinese or Chinese-based element is set to ImOpen; the IMename property value is running at operation. Set by the user. The flexibility of this method is here. In addition, it is necessary to set the value of edit1.text, edit2.text, memo1.lines.

(3) Add a label Label4 in Form1 to set its properties:

CAPTION = Select the favorite input method

Font.size = 12

Font.color = red

(4) Add a drop-down comboBOBOX1 in Form1, select the Events tab in the object viewer Object Inpector, double-click OnDropDown, program the event, the code is as follows:

ComboBox1.Items.commatext: = Screen.imes.commatext;

The above statement can add the Chinese character input method installed in Chinese Windows 95 into the drop-down combo box, which cleverly uses the iMes feature of the Tscreen class, and IMES feature itself is a TSTRING class, its property comMatext contains Windows 95 The installed Chinese character input method can directly assign it to the corresponding attribute of ComboBoX1. If you directly edit ComboBoX1 attribute items to add a Chinese character input method name, the application is unremnible when the application is published, resulting in the unreasonability of the user's Chinese characters input method.

Double-click the OneXIT event in the object viewer and program the event, the code is as follows:

Edit1.imename: = ComboBox1.text;

Memo1.imename: = ComboBox1.text;

(5) Add a command button button1 in Form1 to set its properties to:

CAPTION = Exit

Font.size = 12

Double-click this command button to program the Click event, the code is as follows:

CLOSE;

At this point, the programming process of the entire example is completed, save this application and form, and then compile, run.

3. The use of Chinese character input method

First, select the Chinese characters input method you like, move the cursor to the Chinese input edit box, will find that the selected Chinese character input method is automatically appeared on the screen; then move the cursor to Western input edit box. In the middle, the Chinese character input method will automatically turn off; if the cursor is moved to the Chinese multi-line text editing box, the selected Chinese character input method is automatically appeared.

From the above program, you can set a drop-down combo box for selecting a input method in an entry interface of the application, and allow it to control all the IMENAME properties of all the entry interfaces in the interface, which can be done in the Chinese and Western entry. Do not have to change the retrieval of the entry method during the process, and you can make users choose their favorite Chinese character input method, and this entry interface is also very friendly, convenient and fast. PCC

Must use the 'identifier, but directly using' will be wrong

TDataSet.Filter: = 'SomeBodyname =' CHR (39) 'Lee *' CHR (39)

转载请注明原文地址:https://www.9cbs.com/read-31406.html

New Post(0)