In the Chinese and Western input interfaces of many WINDOWS applications, inputting Chinese and Western requires repeatedly switching the Chinese character input method, which is very cumbersome to use. In the process of developing a certain MIS using DELPHI, the author found a relatively simple solution.
The design environment of this article is DELPHI CLIENT/SERVER SUIT VER3.0 (hereinafter referred to as DELPHI3.0), Chinese WINDOWS'95.
1. Imename and Imemode attributes under DELPHI3.0
In DELPHI3.0, editing components such as Tedit, Tmemo, and TmaskEdit are often used in applications. These three components all have Imename and Imemode attributes. The Imename attribute is the name of the input method. In the object observer, it corresponds to one including all the names in the current system. There is a drop-down combo box for Chinese character input method. The Imemode attribute is the input method mode. It also corresponds to the drop-down combo box in the object observer. The combo box contains six items: imClose, imOpen, imChinese, imDontCare, imSAlpha, and imAlpha:
imClose indicates that the input method is closed.
ImOpen indicates that the input method is open.
ImChinese means it is in Chinese input method state.
ImDontCare means that if the input method is closed, open the latest
Input method used.
ImSAlpha indicates that the input is half-width.
ImAlpha indicates that the input is full-width.
2. Programming of Chinese character input method under DELPHI
In DELPHI3.0, the components involved in input in the Chinese and Western input interface all have Imename and Imemode attributes. When designing the input interface form, assign values to these two attributes of each component, and the system will automatically turn on or off the Chinese character input method you set when the component gets focus. However, this programming method gives users no flexibility at all. If the input method set by the system is not what they are good at, they have to choose it again through the input method selector of WINDOWS'95.
The author solved this problem more flexibly by placing a label and a drop-down combo box under the Form. The Forma in the example placed a total of four Labels, two Edits, a ComboBox, Memo and Button. The following is an example:
1. Select New application under the File menu in DELPHI to generate a new application. Set the properties of the new form Form1
Caption=Input method programming example
2. Add one or two labels Label1, Label2, Label3 and edit boxes Edit1, Edit2, Memo1 in Form1, and set their properties.
Label1.Caption=Chinese input edit box
Label1.Font.Size=12
Label2.Caption= Spanish 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, the ImeMode attribute of components that are input in Spanish or mainly Chinese is generally set to the default value; for components that are input in Chinese or mainly Chinese, the ImeMode attribute is generally set to Imopen, and the ImeName attribute value is set when the program is running. The time is set by the user, and this is where the flexibility of this method lies. In addition, set the values of Edit1.Text, Edit2.Text, and Memo1.Lines to empty.
3. Add a label Label4 to Form1 and set its properties:
Caption = Choose your favorite input method
Font.Size=12
Font.Color=Red
4. Add a drop-down combo box Combobox1 in Form1, select the event column EVENT in the OBJECT INPECTOR, double-click OnDropDown, program this event, and write the following code:
ComboBox1.Items.CommaText:=Screen.Imes.CommaText;
In order to add the Chinese character input method installed in Chinese WINDOWS'95 to the drop-down combo box, the IMES feature of the TSCREEN class is cleverly used, and the IMES feature itself is a TSTRING class, and its attribute Commatext contains Windows'95 For the installed Chinese character input method, directly assign it to the corresponding attribute of ComboBox1. Otherwise, if you directly edit the property Items of ComboBox1 and add the name of the Chinese character input method, the application will not be universal due to the uncertainty of the Chinese character input method on the user's machine when the application is released.
5. Double-click the OnExit event in the object observer and write the following code:
Edit1.Imename:=ComboBox1.Text;
Memo1.Imename:=ComboBox1.Text;
6. Add a command button Button1 in Form1 and set its properties:
Caption=Exit
Font.Size=12
Double-click this command button, program its Click event, and write the following program:
Close;
7. The entire sample program design process is completed, save the application and form, compile and run at this time, the interface is as follows:
First, use the drop-down combo box to select your favorite Chinese character input method, move the cursor to the Chinese input edit box, you will find that the Chinese character input method you selected automatically appears on the screen, and then move the cursor to the Spanish input edit box , the Chinese character input method is automatically closed. If the cursor is placed in the Chinese multi-line text editor, the selected Chinese character input method will automatically appear again.
3. Conclusion
From the above program code, it can be seen that in the input interface of the application, set an input method selection drop-down combo box and let it control the Imename attribute of all input items in the input interface. This can be done without the need for Chinese and Western input. The back-and-forth selection of input methods allows users to choose their favorite Chinese character input method. The input interface is very user-friendly, convenient and fast.