DEPHI program input method in English automatic switching source code

zhaozj2021-02-17  52

Now publish the source code, thank you for your support. I have limited level, what is the inspiration or suggestion of everyone, please email wang517@21cn.com. Thank you! !

The idea of ​​the original code implementation:

Provides a form that lists all input methods of the system for user selection, saving the selected Chinese input method to the system registry.

Provide a method ChangeYouFormAllControlime (Form), Form is a form name that you want to enter, and enumerates a control of the corresponding form has an input method.

Provide a method jugeclasstype (PCLASS: TCONTROL) to determine the actual type of each control, based on its IMEMODE (for the programming, when the value is impHinese, switch to the Chinese input method selected by the user, other switched to English)

Below is the main original code:

// Judgment Control Type Switch in English This can only be specifically determined, unable to discriminate or summarize the TWINCONTROL

procedure JugeClassType (PClass: Tcontrol; beginif pclass is TEdit then begin if TEdit (pclass) .ImeMode = imchinese then TEdit (pclass) .ImeName: = StrImeName (saved StrImeName registry Chinese input Farmington) with) 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 TComboBox then begin if TComboBox (pclass) .ImeMode = imchinese then TComboBox (pclass) .ImeName: = StrImeName else TComboBox (pclass) .ImeMode: = imClose; exit; end; if pclass is TRichEdit then begin if TRichEdit (pclass ) .ImeMode = imchinese then TRichEdit (pclass) .ImeName: = StrImeName else TRichEdit (pclass) .ImeMode: = imClose; exit; end; if pclass is TDBGrid then begin if TDBGrid (pclass) .ImeMode = imchinese then TDBGrid (pclass) .Imename: = Strimename Else TdbGrid (PCLASS) .IMemode: = imclose; exit; end; if pclass is tdbedit the beginning of tdbedit (pclass) .imemode = imchinese then TDBEdit (pclass) .ImeName: = StrImeName else TDBEdit (pclass) .ImeMode: = imClose; exit; end; if pclass is TDbMemo then begin if TDbMemo (pclass) .ImeMode = imchinese then TDbMemo (pclass) .ImeName: = StrImeName else TDbMemo (pclass) .ImeMode: = imClose; exit; end; if pclass is TDbcombobox then begin if TDbcombobox (pclass) .ImeMode = imchinese then TDbcombobox (pclass) .ImeName: = StrImeName else TDbcombobox (pclass) .ImeMode: = Imclose; EXIT; End; if Pclass is TdblookUpComboBox The Begin if TdblookUpComboBox (PCLASS) .IMEMODE = iMCHINESE THEN TDBLOOKUPCOMBOBOX (PCLASS) .imename: =

StrImeName else Tdblookupcombobox (pclass) .ImeMode: = imClose; exit; end; if pclass is Tdbrichedit then 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; // This method, you only need to call in the form on -create event that needs to switch in English. YFORMNAME, you need to switch the form of the Chinese and English.

Procedure ChangeYouFormAllControlIme (YFormName: TWinControl); vari: integer; ChildControl: TControl; Reg: TRegistry; YouFormOrOTher: Twincontrol; beginYouFormOrOTher: = YFormName; reg: = TRegistry.Create; reg.RootKey: = HKEY_LOCAL_MACHINE; try if Reg.OpenKey ( ' / Software / IMeCustom ', false) = true then StrImeName: = reg.ReadString (' CustomIMeName '); finally reg.CloseKey; reg.Free; end; for i: = 0 to YouFormOrOTher.ControlCount-1 do begin ChildControl: = YouFormorother.Controls [i]; jugeclasstype; if ChildControl Is TwinControl The ChangeYouFormallControlime (ChildControl as twinControl); end; end; end.

Enumerate input method, and save the user's choice to the registry, very simple, this can be implemented by himself. E.g

Listbox1.Items: = screen.imes;

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

New Post(0)