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


//--------------------------------------------------------------------------- 
#include "TestSetData.h" 
#include "yb_base.h" 
//--------------------------------------------------------------------------- 
TAppCfg AppCfg; 
//--------------------------------------------------------------------------- 
TAppCfg::TAppCfg() 
{ 
  memset(&Cfg,0,sizeof(TCfgData)); 
} 
//--------------------------------------------------------------------------- 
void TAppCfg::Save(void) 
{ 
  TBinFile f; 
  f.FileName = TRelPath().Extension("cfg"); 
  f.OpenMode = TBinFile::omCreateNew; 
  f.Active = true; 
  f.Write(&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(&Cfg,sizeof(TCfgData)); 
        ApplyLang(); 
        ApplyComm(lpComm); 
        bLoadOK = true; 
      } 
   } 
  catch(Exception &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 }; 
  "语言(&L)"        , //Mnu_Language = { read = fGetMsg, index =  1 }; 
  "串口设置(&S)"    , //Mnu_CommSet  = { read = fGetMsg, index =  2 }; 
  "退出(&X)"        , //Mnu_Exit     = { read = fGetMsg, index =  3 }; 
  "帮助(&H)"        , //Mnu_Help     = { read = fGetMsg, index =  4 }; 
  "关于(&A)"        , //Mnu_About    = { read = fGetMsg, index =  5 }; 
  "发送(&S)"        , //Mnu_Send     = { read = fGetMsg, index =  6 }; 
  "文件(&F)"        , //Mnu_File     = { read = fGetMsg, index =  7 }; 
  "数据(&D)"        , //Mnu_Data     = { read = fGetMsg, index =  8 }; 
}; 
//--------------------------------------------------------------------------- 
 
char *TAppStrings::_Msg_Cht[] = 
{ 
  "串列埠設置演示程式", //Str_AppTitle = { read = fGetMsg, index =  0 }; 
  "語言(&L)"          , //Mnu_Language = { read = fGetMsg, index =  1 }; 
  "串列埠設置(&S)"    , //Mnu_CommSet  = { read = fGetMsg, index =  2 }; 
  "離開(&X)"          , //Mnu_Exit     = { read = fGetMsg, index =  3 }; 
  "幫助(&H)"          , //Mnu_Help     = { read = fGetMsg, index =  4 }; 
  "關於(&A)"          , //Mnu_About    = { read = fGetMsg, index =  5 }; 
  "發送(&S)"          , //Mnu_Send     = { read = fGetMsg, index =  6 }; 
  "檔案(&F)"          , //Mnu_File     = { read = fGetMsg, index =  7 }; 
  "數據(&D)"          , //Mnu_Data     = { read = fGetMsg, index =  8 }; 
}; 
//--------------------------------------------------------------------------- 
 
char *TAppStrings::_Msg_Enu[] = 
{ 
  "ComPort Settings Demo", //Str_AppTitle = { read = fGetMsg, index =  0 }; 
  "&Language"            , //Mnu_Language = { read = fGetMsg, index =  1 }; 
  "Port &Settings"       , //Mnu_CommSet  = { read = fGetMsg, index =  2 }; 
  "E&xit"                , //Mnu_Exit     = { read = fGetMsg, index =  3 }; 
  "&Help"                , //Mnu_Help     = { read = fGetMsg, index =  4 }; 
  "&About"               , //Mnu_About    = { read = fGetMsg, index =  5 }; 
  "&Send"                , //Mnu_Send     = { read = fGetMsg, index =  6 }; 
  "&File"                , //Mnu_File     = { read = fGetMsg, index =  7 }; 
  "&Data"                , //Mnu_Data     = { read = fGetMsg, index =  8 }; 
}; 
//---------------------------------------------------------------------------