BCB 语言类
整理日: 2015年2月16日
EcLanguage.h
/*----------------------------------------------------------------------------*/
// Copy Right : Copyright (C) 2009 XXXXX INC., LTD
// Customer :
// Project :
// Function : Provide multi language function change the UI
// accordingby System Language
// ----------------------------------------------------------------
// File Name : Language.h
// Summary :
// Create : 2009.02.10 by wang
// Modify :
// By : XXXXX INC.,LTD
//
// Modify List : yyyy,mm.dd Xxxxxxxxxxxxxxxxxxxxx by XX.XXXX
/*----------------------------------------------------------------------------*/
//---------------------------------------------------------------------------
#ifndef EcLanguageH
#define EcLanguageH
//---------------------------------------------------------------------------
#include <Forms.hpp>
#include <IniFiles.hpp>
#include <tchar.h>
// Language Class
class TEcLanguage
{
private:
String m_sLangPath; // Language file name
String m_sCurFile;
TStringList* m_pLangs;
TStringList* m_pExts;
String m_sLang;
int m_nCurID;
bool HasProperty(TComponent* aObject,String PropStr);
int GetOperSystemLanID();
protected:
// Load string for control
virtual bool LoadLangFile(TForm* pFrm);
// Save control caption to language file
virtual void SetLangFile(TForm* pFrm);
public:
TEcLanguage(String sConfigPath);
~TEcLanguage();
bool SetLangID(int nID);
int GetCurID(){return m_nCurID;};
TStringList* GetLangs(){return m_pLangs;};
String GetLanFile(){return m_sCurFile;};
// Load UI Language for one form
bool LoadLanguage(TForm* pFrm){return LoadLangFile(pFrm);}
// Save UI string and control size to specific file
void SetLanguage(TForm* pFrm){SetLangFile(pFrm);};
// Load resource string for others except control
String GetStr(int nNo, String sSection=_T("ResourceString"), String sKey=_T("Str"));
};
class TEcLanBug
{
private:
bool HasProperty(TComponent* aObject,String PropStr){return GetPropInfo(aObject, PropStr);};
public:
bool LoadLanguage(TForm* pFrm,String sLanFile);
void SetLanguage(TForm* pFrm,String sLanFile);
};
#endif
EcLanguage.cpp
/*----------------------------------------------------------------------------*/
// Copy Right : Copyright (C) 2009 XXXXX INC., LTD
// Customer :
// Project :
// Function :
// ----------------------------------------------------------------
// File Name : EcLanguage.cpp
// Summary :
// Create : 2009.02.10 by wang
// Modify :
// By : XXXXX INC.,LTD
//
// Modify List : yyyy,mm.dd Xxxxxxxxxxxxxxxxxxxxx by XX.XXXX
/*----------------------------------------------------------------------------*/
#include <vcl.h>
#pragma hdrstop
#include "EcLanguage.h"
#pragma package(smart_init)
TEcLanguage::TEcLanguage(String sConfigPath)
{
// Languageファイルの場所を取って
m_sLangPath = sConfigPath+_T("\\Language\\");
String sLang = m_sLangPath + _T("Lang.ini");
m_pExts = new TStringList;
m_pExts->Clear();
m_pLangs = new TStringList;
m_pLangs->Clear();
TIniFile* iniFile = new TIniFile(sLang);
m_sLang = iniFile->ReadString("General", "AppName", "Daq3");
m_nCurID = iniFile->ReadInteger("General", "CurID", GetOperSystemLanID());
int nLangs = iniFile->ReadInteger("General", "Number", 4);
String sTmp,sTmp1,sTmp2;
for(int i=0;i<nLangs;++i){
sTmp.sprintf(_T("%03d_Ext"),i);
sTmp1 = iniFile->ReadString("Lang", sTmp, "");
if(sTmp1=="") continue;
sTmp.sprintf(_T("%s%s.%s"),m_sLangPath.c_str(),m_sLang.c_str(),sTmp1.c_str());
if(!FileExists(sTmp)) continue;
sTmp.sprintf(_T("%03d_Name"),i);
sTmp2 = iniFile->ReadString("Lang", sTmp, "");
if(sTmp2=="") continue;
m_pExts->Add(sTmp1);
m_pLangs->Add(sTmp2);
}
delete iniFile;
int nCnt = m_pLangs->Count;
if(m_nCurID<0 || m_nCurID>=nCnt)
m_nCurID = 0;
if(nCnt==0){
m_nCurID = -1;
}else{
m_sCurFile.sprintf(_T("%s%s.%s"),m_sLangPath.c_str(),m_sLang.c_str(),m_pExts->Strings[m_nCurID].c_str());
}
}
TEcLanguage::~TEcLanguage()
{
String sLang = m_sLangPath + "Lang.ini";
TIniFile* iniFile = new TIniFile(sLang);
iniFile->WriteInteger("General", "CurID", m_nCurID);
delete iniFile;
delete m_pLangs;
delete m_pExts;
}
// ==========================================================================
// Check specific property in the Object
// return : ture - have the property
// false - have not the property
// ==========================================================================
bool TEcLanguage::HasProperty(TComponent* aObject,String PropStr)
{
return (GetPropInfo(aObject, PropStr) != NULL);
}
// ==========================================================================
// Name : LoadLangFile
// Summary : Load Language string for one form
// Call : LoadLangFile(this);
// Parameter : pFrm : Form object opinter
// Return : true / false
// --------------------------------------------------------------------------
// [modify history]:
// ==========================================================================
bool TEcLanguage::LoadLangFile(TForm* pFrm)
{
if(-1==m_nCurID) return false;
TIniFile* iniFile;
iniFile = new TIniFile(m_sCurFile);
if(!iniFile) return false;
String sComponName = _T("None");
try{
String sTmp;
String sFrmName = pFrm->Name;
if(sFrmName==_T("")){
return false;
}
pFrm->Font->Name = TFontName(iniFile->ReadString(_T("General"), _T("FontName"), _T("Arial")));
pFrm->Font->Charset = TFontCharset(iniFile->ReadInteger(_T("General"), _T("Charset"), 1));
pFrm->Font->Size = iniFile->ReadInteger(_T("General"), _T("FontSize"), 9);
sTmp = iniFile->ReadString(sFrmName,sFrmName,_T(""));
if ((sTmp!=_T("")) && (pFrm->BorderStyle!=bsNone))
pFrm->Caption = sTmp;
TControl* pControl;
TFont* pFont;
int nCount = pFrm->ComponentCount;
for(int ix =0 ;ix<nCount;ix++){
if (HasProperty(pFrm->Components[ix],_T("Caption"))){
sComponName=_T("");
sComponName = pFrm->Components[ix]->Name;
if(sComponName==_T("")) continue;
sTmp = iniFile->ReadString(sFrmName,sComponName,"");
if(sTmp!="")
SetStrProp(pFrm->Components[ix],_T("Caption"), sTmp);
if (!HasProperty(pFrm->Components[ix],_T("ParentFont"))) continue;
pControl =dynamic_cast<TControl*>(pFrm->Components[ix]);
if(((TForm*)pControl)->ParentFont) continue;
pFont = dynamic_cast<TFont*>(GetObjectProp(pControl,_T("Font")));
pFont->Charset = pFrm->Font->Charset;
pFont->Name = pFrm->Font->Name;
SetObjectProp(pFrm->Components[ix],_T("Font"),pFont);
}
//if (HasProperty(pFrm->Components[ix],"ParentFont"))
//{
// pControl =dynamic_cast<TControl*>(pFrm->Components[ix]);
// if(((TForm*)pControl)->ParentFont) continue;
//
// pFont = dynamic_cast<TFont*>(GetObjectProp(pControl,"Font"));
// pFont->Charset = pFrm->Font->Charset;
// pFont->Name = pFrm->Font->Name;
// SetObjectProp(pFrm->Components[ix],"Font",pFont);
//
//}
}
pFrm->Update();
}catch (Exception &exception){
Application->ShowException(&exception);
}catch (...){
try{
throw Exception("");
}catch (Exception &exception){
Application->ShowException(&exception);
}
}
delete iniFile;
return true;
}
// ==========================================================================
// Name : SetLangFile
// Summary : Save controls stirng of form to Language file
// Call : SetLangFile(this);
// Parameter : pFrm : Form object opinter
// Return : void
// --------------------------------------------------------------------------
// [modify history]:
// ==========================================================================
void TEcLanguage::SetLangFile(TForm* pFrm)
{
if(-1==m_nCurID) return;
String sCaption;
TIniFile* iniFile = new TIniFile(m_sCurFile);
try{
iniFile->WriteString(pFrm->Name,pFrm->Name,pFrm->Caption);
iniFile->WriteInteger("General", "Charset", pFrm->Font->Charset);
iniFile->WriteString("General", "FontName", pFrm->Font->Name);
iniFile->WriteInteger("General", "FontSize", pFrm->Font->Size);
for(int ix =0 ;ix< pFrm->ComponentCount;ix++){
if (HasProperty(pFrm->Components[ix],_T("Caption")) ){
sCaption = GetStrProp(pFrm->Components[ix],_T("Caption"));
if(sCaption!=""){
iniFile->WriteString(pFrm->Name,pFrm->Components[ix]->Name,sCaption);
}
}
}
}catch (Exception &exception){
Application->ShowException(&exception);
}catch (...){
try{
throw Exception("");
}catch (Exception &exception){
Application->ShowException(&exception);
}
}
delete iniFile;
}
// ==========================================================================
// Name : GetResourceString
// Summary : Get one resource string to language file
// Call : GetResourceString(Str1,"Form1")
// Parameter : TmpStr : resoruce string
// SectionStr : Section string of ini file
// Return : string which read form the language file
// --------------------------------------------------------------------------
// [modify history]:
// ==========================================================================
String TEcLanguage::GetStr(int nNo, String sSection, String sKey)
{
if(-1==m_nCurID) return "***";
String sText;
TIniFile* iniFile = new TIniFile(m_sCurFile);
sKey.sprintf(_T("%s%03d"),sKey.c_str(),nNo);
sText = iniFile->ReadString(sSection,sKey,"");
delete iniFile;
return sText;
}
// ==========================================================================
// Name : GetOperSystemLanID
// Summary : get system language ID;
// Call : GetOperSystemLanID();
// Parameter : None;
// Return : int
// --------------------------------------------------------------------------
// [modify history]:
// ==========================================================================
int TEcLanguage::GetOperSystemLanID()
{
LCID lanid = GetSystemDefaultLCID(); //API fun
int nlanid = lanid;
int nLanType = 0;
char szLan[10];
itoa(nlanid,szLan,16);
//english
if (strcmp(szLan,"409")==0) nLanType=0;
//simple chinese language
if (strcmp(szLan,"804")==0) nLanType=1;
//japan language
if (strcmp(szLan,"411")==0) nLanType=2;
//complicated chinese language
if (strcmp(szLan,"404")==0) nLanType=3;
//Spanish (Traditional Sort) language
if (strcmp(szLan,"40a")==0) nLanType=4;
//Spanish (Mexican) language
if (strcmp(szLan,"80a")==0) nLanType=4;
return nLanType;
}
bool TEcLanguage::SetLangID(int nID)
{
if(m_nCurID==nID) return false;
m_nCurID = nID;
m_sCurFile.sprintf(_T("%s%s.%s"),m_sLangPath.c_str(),m_sLang.c_str(),m_pExts->Strings[m_nCurID].c_str());
return true;
}
bool TEcLanBug::LoadLanguage(TForm* pFrm,String sLanFile)
{
TIniFile* iniFile;
iniFile = new TIniFile(sLanFile);
if(!iniFile) return false;
try{
String sTmp;
pFrm->Font->Name = TFontName(iniFile->ReadString("General", "FontName", "Arial"));
pFrm->Font->Size = iniFile->ReadInteger("General", "FontSize", 9);
pFrm->Font->Charset = TFontCharset(iniFile->ReadInteger("General", "Charset", 1));
sTmp = iniFile->ReadString(pFrm->Name,pFrm->Name,"");
if(sTmp!="") pFrm->Caption = sTmp;
TControl* pControl;
TFont* pFont;
for(int ix =0 ;ix<pFrm->ComponentCount;ix++){
if (HasProperty(pFrm->Components[ix],"Caption")){
sTmp = iniFile->ReadString(pFrm->Name,pFrm->Components[ix]->Name,"");
if(sTmp!="")
SetStrProp(pFrm->Components[ix],"Caption", sTmp);
if (!HasProperty(pFrm->Components[ix],"ParentFont")) continue;
pControl =dynamic_cast<TControl*>(pFrm->Components[ix]);
if(((TForm*)pControl)->ParentFont) continue;
pFont = dynamic_cast<TFont*>(GetObjectProp(pControl,"Font"));
pFont->Charset = pFrm->Font->Charset;
pFont->Name = pFrm->Font->Name;
SetObjectProp(pFrm->Components[ix],"Font",pFont);
}
//if (HasProperty(pFrm->Components[ix],"ParentFont"))
//{
// pControl =dynamic_cast<TControl*>(pFrm->Components[ix]);
// if(((TForm*)pControl)->ParentFont) continue;
//
// pFont = dynamic_cast<TFont*>(GetObjectProp(pControl,"Font"));
// pFont->Charset = pFrm->Font->Charset;
// pFont->Name = pFrm->Font->Name;
// SetObjectProp(pFrm->Components[ix],"Font",pFont);
//
//}
}
pFrm->Update();
}catch (Exception &exception){
Application->ShowException(&exception);
}catch (...){
try{
throw Exception("");
}catch (Exception &exception){
Application->ShowException(&exception);
}
}
delete iniFile;
return true;
}
void TEcLanBug::SetLanguage(TForm* pFrm,String sLanFile)
{
String sCaption;
TIniFile* iniFile = new TIniFile(sLanFile);
try{
iniFile->WriteString(pFrm->Name,pFrm->Name,pFrm->Caption);
iniFile->WriteInteger("General", "Charset", pFrm->Font->Charset);
iniFile->WriteString("General", "FontName", pFrm->Font->Name);
iniFile->WriteInteger("General", "FontSize", pFrm->Font->Size);
for(int ix =0 ;ix< pFrm->ComponentCount;ix++){
if (HasProperty(pFrm->Components[ix],_T("Caption")) ){
sCaption = GetStrProp(pFrm->Components[ix],_T("Caption"));
if(sCaption!=""){
iniFile->WriteString(pFrm->Name,pFrm->Components[ix]->Name,sCaption);
}
}
}
}catch (Exception &exception){
Application->ShowException(&exception);
}catch (...){
try{
throw Exception("");
}catch (Exception &exception){
Application->ShowException(&exception);
}
}
delete iniFile;
}
BCB 语言类的更多相关文章
- OC语言类的本质和分类
OC语言类的深入和分类 一.分类 (一)分类的基本知识 概念:Category 分类是OC特有的语言,依赖于类. 分类的作用:在不改变原来的类内容的基础上,为类增加一些方法. 添加一个分类: 文件 ...
- 李洪强iOS开发之OC语言类的深入和分类
OC语言类的深入和分类 一.分类 (一)分类的基本知识 概念:Category 分类是OC特有的语言,依赖于类. 分类的作用:在不改变原来的类内容的基础上,为类增加一些方法. 添加一个分类: 文件 ...
- 模块的封装之C语言类的封装
[微知识]模块的封装(一):C语言类的封装 是的,你没有看错,我们要讨论的是C语言而不是C++语言中类的封装.在展开知识点之前,我首先要 重申两点: 1.面向对象是一种思想,基本与所用的语言是无关的. ...
- 模块的封装之C语言类的继承和派生
[交流][微知识]模块的封装(二):C语言的继承和派生 在模块的封装(一):C语言的封装中,我们介绍了如何使用C语言的结构体来实现一个类的封装,并通过掩码结构体的方式实 现了类成员的保护.这一部分,我 ...
- 设计一个网上书店,该系统中所有的计算机类图书(ComputerBook)每本都有10%的折扣,所有的语言类图书(LanguageBook)每本都有2元的折扣,小说类图书(NovelBook)每100元
现使用策略模式来设计该系统,绘制类图并编程实现 UML类图 书籍 package com.zheng; public class Book { private double price;// 价格 p ...
- iOS学习之Object-C语言类和对象
一.OC语言的特点:封装,继承,多态:包含一个运行时系统:类库丰富. 二.面向对象 1.概述 OOP(Object Oriented Programming)面向对象编程. ...
- SQL语言类
SQL语分为四类:数据查询语言DQL,数据操纵语言DML. 数据定义语言DDL,数据控制语言DCL. 1 数据查询语言DQL 数据查询语言DQL基本结构是由SELECT子句.FROM子句,WHE ...
- C#语言——类
C#——类 一.String 类 系统内置的处理字符串类型的函数方法类.方便我们对字符串类型进行一系列的处理. 1.Length:获取字符串的长度,返回一个int类型的值 string x=Conso ...
- 黑马程序员——OC语言 类和对象
Java培训.Android培训.iOS培训..Net培训.期待与您交流! (以下内容是对黑马苹果入学视频的个人知识点总结) (一)类 1)类的声明 代码编写 ①定义一个Car类,拥有2个属性:轮子数 ...
随机推荐
- BZOJ 2754([SCOI2012]喵喵叫的星球-统计序列的后缀阵列中子序列出现次数)
2754: [SCOI2012]喵喵叫的星球 Time Limit: 20 Sec Memory Limit: 128 MB Submit: 805 Solved: 380 [id=2754&qu ...
- Html学习笔记4
<span style="font-size:18px;">超链接: 1 标签 语法: <a href="链接跳转后的地址 " >链接文 ...
- C和指针 (pointers on C)——第四章:语句(上)
第四章--语句(上) 总结总结!!! C没有布尔类型,所以在一些逻辑推断时候必须用整型表达式,零值为假,非零值为真. for比while把控制循环的表达式收集起来放在一个地方,以便寻找. do语句比w ...
- Android实战技巧之六:PreferenceActivity使用详解
一.写作前面 当我们做应用的时候,需要用户配置一些信息,而这就是通常所说的应用设置. 对于Android系统来说,系统本身的设置带来的用户体验和习惯已经深入人心,在我们的应用中同样用到类似的设置页, ...
- myeclipse 编码问题
在使用eclipse+MyEclipse开发中,许多文件编码默认是ISO-8859-1,不支持中文(如常用的JSP),这样我们每次建文件都要手动改编码,其实我们可以在设置文件默认编码,今后再创建时就不 ...
- Linux下搭建Oracle11g RAC(1)----IP分配与配置IP
首先需要说明的,我的RAC搭建不是在虚拟机上完成的,而是在实际部署中,二者之间有些许差异,本人水平有限,请见谅. 其中,每台机器至少需要配置3个IP地址,在安装操作系统的过程中,我们需要配置公网IP和 ...
- GUI编程笔记(java)10:GUI实现一级菜单
1.首先:菜单组件 MenuBar,Menu,MenuItem 先创建菜单条,再创建菜单,每一个菜单中建立菜单项. 也可以菜单添加到菜单中,作为子菜 ...
- JavaScript 应用开发 #5:为完成的任务添加样式
判断一下任务的状态,如果是完成的任务,可以在任务项目的上面,添加一个额外的 css 类,在这个 css 类里,可以去定义完成的任务的样式.比如,把文字的颜色变成浅友色,并且在文字上面添加一条删除线.这 ...
- Linux终端Ctrl相关快捷键
快速跳至行首:Ctrl+A 快速跳至行尾:Ctrl+E 向前删除至行首:Ctrl+U 向后删除至行尾:Ctrl+K 向后删一个单词:Ctrl+D 清屏:Crtl+L(clear)
- C#中的委托范例学习
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...