DELPHI2010开发多语言界面的方法。

DELPHI2010开发多语言界面的方法。
只需要下面3个方法就可以实现了。


//判断某一个公开属性是否存在。引用单元 use typinfo;
Function TSeverForm.HasProperty(AComponent : TComponent;APropertyName : string) :boolean;
begin


 //本方法主要是用于判断控件的CAPTION,HINT,TITLE,TEXT属性是否存在。
  if Assigned(GetPropInfo(AComponent.Classinfo,APropertyName)) then
    Result := True
    else
    Result := False;
end;

//切换界面语言的方法,窗体加载是调用一次。
Procedure TSeverForm.ActiveLanguageIni(LanguangeFile : String);
Var i : Integer;
    proValue : String;
begin
  for I := 0 to Self.ComponentCount-1 do
    begin
    if HasProperty(Components[i],'Caption') then
      begin
      proValue := ReadIniFile(LanguangeFile,Self.Name, Components[i].Name+'.Caption','');
      if proValue<>'' then SetStrProp(Components[i],'Caption',proValue);
      end;
    if HasProperty(Components[i],'Hint') then
      begin
      proValue := ReadIniFile(LanguangeFile,Self.Name, Components[i].Name+'.Hint','');
      if proValue<>'' then SetStrProp(Components[i],'Hint',proValue);
      end;
    end;
end;


//生成初始的界面语言切换所需文件
Procedure TSeverForm.SaveLanguageIni(LanguangeFile : String);
Var i : Integer;
begin
//用此方法生成3个文件:中文简体CHinese.ini,中文繁体ChineseBig5.INI,英文English.Ini,然后修改Ini文件对应控件的译文,与应用程序一起发布。
  for I := 0 to Self.ComponentCount-1 do
    begin
    if HasProperty(Components[i],'Caption') then
       begin
       if GetStrProp(Components[i],'Caption')<>'' then
          WriteIniFile(LanguangeFile,Self.Name, Components[i].Name+'.Caption',GetStrProp(Components[i],'Caption') );
       end;
    if HasProperty(Components[i],'Hint') then
       begin
       if GetStrProp(Components[i],'Hint')<>'' then
          WriteIniFile(LanguangeFile,Self.Name,Components[i].Name+'.Hint',GetStrProp(Components[i],'Hint') );
       end;
    end;






评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值