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

来源:互联网 发布:时时彩单双计划软件 编辑:程序博客网 时间:2024/06/05 03:06
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;






原创粉丝点击