dephi 程序输入法中英文自动切换实现

程序员只需要将窗体中该输入中文的控件的 imemode=imchinese,然后在每个窗体里 create(或active) 事件里调用本人编写的方法changeyouformallcontrolime(frm)即可.在程序中提供一个用户输入法选项供用户选择自己喜欢的输入法,调用显示frmimenamelist 窗体即可!总之,程序员只需要调用 一个公用 unit(含有窗体的unit) 下的方法: changeyouformallcontrolime(yformname:twincontrol), 调用显示窗体 frmimenamelist

实现方法: unit 名字 unitimemanager 包含的窗体名字 frmimenamelist

界面操作的代码:

procedure tfrmimenamelist.formcreate(sender: tobject); //列表框加载系统输入法

begin

listbox1.items:=screen.imes;

end;
 procedure tfrmimenamelist.bitbtn1click(sender: tobject);//保存用户选择的输入法存放到系统注册表里面

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:='中文 (简体) - 智能 abc';

try

 if reg.openkey('\software\imecustom', true)  then reg.writestring('customimename',custimename);

finally

 reg.closekey;

 reg.free;

end;

frmimenamelist.close;

end;

原代码实现的思路: 。

提供一个列举系统所有输入法的窗体,供用户选择,将选择的中文输入法保存到系统注册表里。 .

提供一个方法 ChangeYouFormAllControlIme(form) ,form 是需要输入的窗体名称,枚举出相应窗体具有输入法的控件。 特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系.

提供一个方法 JugeClassType(PClass:Tcontrol),判断每一个控件的实际类型,根据其ImeMode(为了程序设计简便,当值 为imchinese 时,切换为用户选择的中文输入法 ,其它切换为英文) .

下面是主要原代码: ...

//判断控件类型切换中英文这个只能具体判断,无法用 Twincontrol 笼统判别或概括 .

procedure JugeClassType(PClass:Tcontrol;
begin
if pclass is TEdit then
begin
if TEdit(pclass).ImeMode=imchinese then
TEdit(pclass).ImeName:=StrImeName (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 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 then
begin
if 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 then
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; 

 

功的人生,需要自己去经营,别再说了,莫再等了,现在就为自己的人生做好规划,为人生点亮一盏明灯,赢在人生起跑点上。

//这个方法,您只需要在需要切换中英文的窗体 oncreate 事件里调用就可以了。YFormName,需要切换中英文的窗体。 ...

Procedure ChangeYouFormAllControlIme(YFormName:TWinControl);
var
i:integer;
ChildControl:TControl;
Reg:TRegistry;
YouFormOrOTher:Twincontrol;
begin
YouFormOrOTher:=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(ChildControl);
if ChildControl is TWinControl then ChangeYouFormAllControlIme(ChildControl as TWinControl);
end;
end;
end. 

枚举输入法,并将用户的选择保存到注册表里,很简单,这个大家可以自己实现。例如 根据专家观察,这样的理论和现象都是值得各位站长深思的,所以希望大家多做研究学习,争取总结出更多更好的经验!

ListBox1.Items:=screen.Imes;


转载于:https://www.cnblogs.com/xiaobao/archive/2010/09/01/1815020.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi 是一种编程语言和集成开发环境(IDE),由 Borland 公司开发。要实现 Delphi 程序自动更新,可以采用以下几个步骤: 1. 获取当前程序版本:在程序中添加一个函数或方法,用于获取程序的当前版本号。可以将版本号存储在配置文件中或者在代码中硬编码。 2. 检查最新版本:程序运行时,可以向服务器发送请求,获取服务器上存储的最新版本号。可以使用网络库或其他通信机制,发送请求并接收服务器的响应。 3. 比较版本号:将服务器返回的最新版本号与当前程序的版本号进行比较。如果最新版本号大于当前版本号,说明有新版本可用,需要更新程序。 4. 下载更新文件:从服务器下载更新文件。可以使用网络库或其他下载库,将更新文件下载到本地。 5. 执行更新:将下载的更新文件保存在本地,并根据需要进行文件解压、复制等操作。可以使用 Delphi 提供的文件处理函数和组件进行文件操作。 6. 重启程序:在更新完成后,可以提示用户是否立即重启程序。如果用户同意,可以通过 Delphi 提供的相关接口或函数,重新启动程序。 需要注意的是,自动更新需要有一个可信任的服务器,存储最新的程序版本和更新文件。同时还需要处理好网络连接异常、文件完整性校验、用户权限等各种边界情况。此外,确保在更新过程中数据的安全性,避免未经授权的修改或破坏。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值