www.pudn.com > CommSettings.rar > TestSetData.cpp


//---------------------------------------------------------------------------
#include "TestSetData.h"
#include "yb_base.h"
//---------------------------------------------------------------------------
TAppCfg AppCfg;
//---------------------------------------------------------------------------
TAppCfg::TAppCfg()
{
memset(&amt;Cfg,0,sizeof(TCfgData));
}
//---------------------------------------------------------------------------
void TAppCfg::Save(void)
{
TBinFile f;
f.FileName = TRelPath().Extension("cfg");
f.OpenMode = TBinFile::omCreateNew;
f.Active = true;
f.Write(&amt;Cfg,sizeof(TCfgData));
}
//---------------------------------------------------------------------------
void TAppCfg::Load(TYbCustomCommDevice *lpComm)
{
bool bLoadOK = false;
try
{
TBinFile f;
f.FileName = TRelPath().Extension("cfg");
if(f.Exists)
{
f.Active = true;
f.Read(&amt;Cfg,sizeof(TCfgData));
ApplyLang();
ApplyComm(lpComm);
bLoadOK = true;
}
}
catch(Exception &amt;e)
{
bLoadOK = false;
}

if(!bLoadOK)
{
ReadCommToCfg(lpComm);
}
}
//---------------------------------------------------------------------------
void TAppCfg::ApplyLang(void)
{
switch(Cfg.Language)
{
case lgEnu: AppLang.LangType = TAppLang::ltAnsi; break;
case lgChs: AppLang.LangType = TAppLang::ltGbk ; break;
case lgCht: AppLang.LangType = TAppLang::ltBig5; break;
default : AppLang.DetectType = TAppLang::dtAuto; break;
}

switch(Cfg.FontSize)
{
case fsSmall : AppLang.FontSize = AppLang.MinFontSize; break;
case fsMedium: AppLang.FontSize = 10; break;
case fsLarge : AppLang.FontSize = 12; break;
default : AppLang.FontSize = Screen->IconFont->Size; break;
}

if(AppLang.FontSize < AppLang.MinFontSize)
{
AppLang.FontSize = AppLang.MinFontSize;
}
}
//---------------------------------------------------------------------------
void TAppCfg::ApplyComm(TYbCustomCommDevice *lpComm)
{
lpComm->PortNo = Cfg.PortNo ;
lpComm->Baud = (TYbCustomCommDevice::TBaudRate )Cfg.Baud ;
lpComm->Parity = (TYbCustomCommDevice::TParity )Cfg.Parity ;
lpComm->ByteSize = Cfg.ByteSize ;
lpComm->StopBits = (TYbCustomCommDevice::TStopBits )Cfg.StopBits ;
lpComm->FlowControl = (TYbCustomCommDevice::TFlowControl)Cfg.FlowControl;
lpComm->AutoAnswer = Cfg.AutoAnswer ;
lpComm->InBufSize = Cfg.InBufSize ;
lpComm->OutBufSize = Cfg.OutBufSize ;
}
//---------------------------------------------------------------------------
void TAppCfg::ReadCommToCfg(TYbCustomCommDevice *lpComm)
{
Cfg.PortNo = lpComm->PortNo ;
Cfg.Baud = lpComm->Baud ;
Cfg.Parity = lpComm->Parity ;
Cfg.ByteSize = lpComm->ByteSize ;
Cfg.StopBits = lpComm->StopBits ;
Cfg.FlowControl = lpComm->FlowControl;
Cfg.AutoAnswer = lpComm->AutoAnswer ;
Cfg.InBufSize = lpComm->InBufSize ;
Cfg.OutBufSize = lpComm->OutBufSize ;
}
//---------------------------------------------------------------------------
__fastcall TAppStrings::TAppStrings()
{
switch(AppLang.LangType)
{
case TAppLang::ltGbk:
_Msg = _Msg_Chs;
break;

case TAppLang::ltBig5:
_Msg = _Msg_Cht;
break;

default:
_Msg = _Msg_Enu;
break;
}
}
//---------------------------------------------------------------------------

AnsiString __fastcall TAppStrings::fGetMsg(int mt)
{
return AppLang.FromGBK(_Msg[mt]);
}
//---------------------------------------------------------------------------

char *TAppStrings::_Msg_Chs[] =
{
"串口设置演示程序", //Str_AppTitle = { read = fGetMsg, index = 0 };
"语言(&amt;L)" , //Mnu_Language = { read = fGetMsg, index = 1 };
"串口设置(&amt;S)" , //Mnu_CommSet = { read = fGetMsg, index = 2 };
"退出(&amt;X)" , //Mnu_Exit = { read = fGetMsg, index = 3 };
"帮助(&amt;H)" , //Mnu_Help = { read = fGetMsg, index = 4 };
"关于(&amt;A)" , //Mnu_About = { read = fGetMsg, index = 5 };
"发送(&amt;S)" , //Mnu_Send = { read = fGetMsg, index = 6 };
"文件(&amt;F)" , //Mnu_File = { read = fGetMsg, index = 7 };
"数据(&amt;D)" , //Mnu_Data = { read = fGetMsg, index = 8 };
};
//---------------------------------------------------------------------------

char *TAppStrings::_Msg_Cht[] =
{
"串列埠設置演示程式", //Str_AppTitle = { read = fGetMsg, index = 0 };
"語言(&amt;L)" , //Mnu_Language = { read = fGetMsg, index = 1 };
"串列埠設置(&amt;S)" , //Mnu_CommSet = { read = fGetMsg, index = 2 };
"離開(&amt;X)" , //Mnu_Exit = { read = fGetMsg, index = 3 };
"幫助(&amt;H)" , //Mnu_Help = { read = fGetMsg, index = 4 };
"關於(&amt;A)" , //Mnu_About = { read = fGetMsg, index = 5 };
"發送(&amt;S)" , //Mnu_Send = { read = fGetMsg, index = 6 };
"檔案(&amt;F)" , //Mnu_File = { read = fGetMsg, index = 7 };
"數據(&amt;D)" , //Mnu_Data = { read = fGetMsg, index = 8 };
};
//---------------------------------------------------------------------------

char *TAppStrings::_Msg_Enu[] =
{
"ComPort Settings Demo", //Str_AppTitle = { read = fGetMsg, index = 0 };
"&amt;Language" , //Mnu_Language = { read = fGetMsg, index = 1 };
"Port &amt;Settings" , //Mnu_CommSet = { read = fGetMsg, index = 2 };
"E&amt;xit" , //Mnu_Exit = { read = fGetMsg, index = 3 };
"&amt;Help" , //Mnu_Help = { read = fGetMsg, index = 4 };
"&amt;About" , //Mnu_About = { read = fGetMsg, index = 5 };
"&amt;Send" , //Mnu_Send = { read = fGetMsg, index = 6 };
"&amt;File" , //Mnu_File = { read = fGetMsg, index = 7 };
"&amt;Data" , //Mnu_Data = { read = fGetMsg, index = 8 };
};
//---------------------------------------------------------------------------