Foreword
:
When our software delivery user is used, the user needs to be frequently switched between Chinese and English, and the input method used by the user is different. Some is five strokes, some are pinyin, etc. We can Provides a personalized input method selection in the software? When the user selects the input method you like, the input in the program is automatically switched to Chinese, and the input English is automatically switched to English.
This implementation method is more, but it is very troublesome, so although many programmers can be realized, they are very troublesome! Below is a very simple and easy to use solution.
Solutions:
The programmer only needs to turn the IMEMODE = IMCHINESE of the input in the form in the form, and then call the method ChangeouFormallControlime (FRM) written in the Create (or Active) event in each form. Provide a user in the program Input method options for users to choose their favorite input method, call the display frmimenamelist form! In short, programmers only need to call a public Unit (Unit) method: ChangeYouFormAllControlime (YFormName: TwinControl), call display FRMIMENAMELIST
Implementation method: Unit name UnitimeManager contains FRMIMENAMELIST
Common Unit form interface:
Interface operation code:
Procedure tfrmimenamelist.formcreate (sender: TOBJECT); / / list box load system input method
Begin
Listbox1.Items: = screen.imes;
END;
Procedure tfrmimimenamelist.bitbtn1click (sender: TOBJECT); / / Save the user-selected input method to store it in the system registry
VAR
REG: TREGISTRY;
Custimename: String;
Begin
REG: = Tregistry.create;
REG.ROOTKEY: = HKEY_LOCAL_MACHINE
IF ListBox1.ItemIndex <> - 1 THEN
Custimename: = ListBox1.items [listbox1.itemindex]
Else
Custimename: = 'Chinese (Simplified) - Intelligent ABC'
Try
If reg.openkey ('/ software / imcustom', true) THEN REG.WRITESTRING ('Customimename', Custimename);
Finally
REG.CLOSEKEY;
Reg.free;
END;
Frmimenamelist.close;
END;
Method of public Unit:
1 Change the input method of all controls in the corresponding form
Procedure Chang (YFormName: TwinControl); // Need to change the form name of the input method
VAR
i: integer;
ChildControl: tcontrol;
REG: TREGISTRY;
YouFormorother: TwinControl;
Begin
YouFormorother: = YFORMNAME;
REG: = Tregistry.create;
/ / Read the input method selected by the user saved by the registry, save the unit global variable Strimename
REG.ROOTKEY: = HKEY_LOCAL_MACHINE
Try
If reg.openkey ('/ Software / IMECUSTOM', FALSE) = True Then
Strimename: = reg.readstring ('Customimename');
Finally
REG.CLOSEKEY;
Reg.free;
END;
// Call Method JugeClasStype (ChildControl) Change the IMEMODE of the control in the form
For i: = 0 to youformorother.ControlCount-1 DO
Begin
ChildControl: = YouFormorother.Controls [i];
JugeClasStype (ChildControl);
// If the control contains controls, change the contained control
If ChildControl Is TwinControl Then ChangeYouFormallControlime (ChildControl as twinControl);
END;
END;
2 Judgment the control category, change its IMEMODE attribute for the input method selected by the user
Procedure JugeClassType (PCLASS: TCONTROL); // Although it is trouble, it must be specifically determined, the following will almost all contain the control, not included, the use value is not large.
Begin
If PCLASS IS TEDIT THEN / / Change the TEDIT Class Control Same Saix
Begin
IF TEDIT (PCLASS). IMEMODE = Imchinese Then
Tedit (PCLASS) .imename: = Strimename
Else
Tedit (PCLASS) .imemode: = imclose;
EXIT;
END;
IF pclass is Tmemo Then
Begin
IF TMEMO (PCLASS). IMEMODE = Imchinese Then
TMEMO (PCLASS) .imename: = Strimename
Else
TMEMO (PCLASS) .IMEMODE: = Imclose;
EXIT;
END;
IF pclass is tcomboBOBOX THEN
Begin
IF Tcombobox (PCLASS) .imemode = Imchinese Then
Tcombobox (pclass) .imename: = Strimename
Else
TcomboBox (PCLASS) .imemode: = imclose;
EXIT;
END;
IF pclass is trichedit.
Begin
if TrichEdit (PCLASS) .imeMode = Imchinese Then
Trichedit (PCLASS) .imename: = Strimename
Else
TrichEdit (PCLASS) .imemode: = imclose;
EXIT;
END;
IF pclass is tdbgrid the
Begin
IF TDBGRID (PCLASS). IMEMODE = Imchinese Then
TDBGRID (PCLASS) .imename: = Strimename
Else
TDBGRID (PCLASS) .IMEMode: = Imclose
EXIT;
END;
IF pclass is tdbedit.
Begin
If tdbedit (pclass) .imemode = imchinese then
TDBEDIT (PCLASS) .imename: = Strimename
Else
TDBEDIT (PCLASS) .IMEMODE: = Imclose;
EXIT;
END;
IF pclass is tdbmemo the
Begin
IF TDBMEMO (PCLASS). IMEMODE = Imchinese Then
TDBMEMO (PCLASS) .imename: = Strimename
Else
TDBMEMO (PCLASS) .IMEMode: = Imclose;
EXIT;
END;
IF pclass is tdbcomboboBOBOX THENBEGIN
IF TDBCOMBOBOX (PCLASS) .IMemode = Imchinese Then
TDBCOMBOBOX (PCLASS) .imename: = Strimename
Else
TDBCOMBOBOX (PCLASS) .IMemode: = Imclose;
EXIT;
END;
IF pclass is tdblookuppcomboBOX THEN
Begin
IF TDBlookuppComboBox (PCLASS) .IMemode = Imchinese Then
TdblookuppComboBox (PCLASS) .imename: = Strimename
Else
TdblookuppComboBox (PCLASS) .imemode: = iMClose
EXIT;
END;
IF pclass is tdbrichedit the
Begin
IF TDBRICHEDIT (PCLASS) .IMemode = Imchinese Then
TdbricheDit (PCLASS) .imename: = Strimename
Else
TDBRICHEDIT (PCLASS) .IMEMODE: = Imclose;
EXIT;
END;
IF pclass is tmaskedit then
Begin
IF Tmaskedit (PCLASS) .IMemode = Imchinese Then
Tmaskedit (PCLASS) .imename: = Strimename
Else
Tmaskedit (PCLASS) .imemode: = imclose;
EXIT;
END;
END;