📄 yb_base.cpp
字号:
void TVictorStringList::fSetValue(TVictorString sItem, TVictorString sNewValue)
{
int n = Count;
TVictorString sName, sOldValue, sUpperItem=sItem.UpperCase();
for(int idx=0; idx<n; idx++)
{
fStrToNameValue(Item[idx], sName, sOldValue);
if(sName.UpperCase()==sUpperItem)
{
Item[idx] = sItem+"="+sNewValue;
return;
}
}
Add(sItem+"="+sNewValue); //Add a new value
}
//----------------------------------------------------------------------------
void TVictorStringList::fStrToNameValue(TVictorString s, TVictorString &n, TVictorString &v) const
{
int p = s.Pos("=");
if(p>=0)
{
n=s.Left(p);
v=s.SubString(p+1,-1);
}
else
{
n=s;
v.Clear();
}
}
//----------------------------------------------------------------------------
int TVictorStringList::IndexOf(TVictorString s) //-1: not found
{
int n = Count;
for(int i=0; i<n; i++)
{
if(Item[i] == s)
return i;
}
return -1;
}
//----------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
TVictorWideStringList::TVictorWideStringList()
{
}
//----------------------------------------------------------------------------
TVictorWideStringList::TVictorWideStringList(TVictorWideString s)
{
Text = s;
}
//----------------------------------------------------------------------------
TVictorWideStringList::TVictorWideStringList(const TVictorWideStringList &sl)
{
Text = sl.Text;
}
//----------------------------------------------------------------------------
TVictorWideString TVictorWideStringList::fGetItem(int idx)const
{
if((idx>=0)&&(idx<Count))
return _Items[idx];
return TVictorWideString();
}
//----------------------------------------------------------------------------
void TVictorWideStringList::fSetItem(int idx, const TVictorWideString &s)
{
if((idx>=0)&&(idx<Count))
_Items[idx] = s;
}
//----------------------------------------------------------------------------
void TVictorWideStringList::Add(TVictorWideString s)
{
_Items.push_back(s);
}
//----------------------------------------------------------------------------
void TVictorWideStringList::Insert(TVictorWideString s, int idx)
{
_Items.insert(_Items.begin()+idx,s);
}
//----------------------------------------------------------------------------
void TVictorWideStringList::Delete(int idx)
{
_Items.erase(_Items.begin()+idx);
}
//----------------------------------------------------------------------------
TVictorWideString TVictorWideStringList::fGetText(void)const
{
int n = Count;
TVictorWideString s;
for(int i=0; i<n; i++)
s+=Item[i]+"\r\n";
return s;
}
//----------------------------------------------------------------------------
void TVictorWideStringList::fSetText(TVictorWideString s)
{
Clear();
int p = s.Pos("\r\n"); //0123pp678
while(p>=0)
{
Add(s.Left(p));
s = s.SubString(p+2,-1);
p = s.Pos("\r\n");
}
if(!s.IsEmpty())Add(s);
}
//----------------------------------------------------------------------------
TVictorWideString TVictorWideStringList::fGetValue(TVictorWideString sItem) const
{
int n = Count;
TVictorWideString sName, sValue, sUpperItem=sItem.UpperCase();
for(int idx=0; idx<n; idx++)
{
fStrToNameValue(Item[idx], sName, sValue);
if(sName.UpperCase()==sUpperItem)
return sValue;
}
return TVictorWideString();
}
//----------------------------------------------------------------------------
void TVictorWideStringList::fSetValue(TVictorWideString sItem, TVictorWideString sNewValue)
{
int n = Count;
TVictorWideString sName, sOldValue, sUpperItem=sItem.UpperCase();
for(int idx=0; idx<n; idx++)
{
fStrToNameValue(Item[idx], sName, sOldValue);
if(sName.UpperCase()==sUpperItem)
{
Item[idx] = sItem+"="+sNewValue;
return;
}
}
Add(sItem+"="+sNewValue); //Add a new value
}
//----------------------------------------------------------------------------
void TVictorWideStringList::fStrToNameValue(TVictorWideString s, TVictorWideString &n, TVictorWideString &v) const
{
int p = s.Pos("=");
if(p>=0)
{
n=s.Left(p);
v=s.SubString(p+1,-1);
}
else
{
n=s;
v.Clear();
}
}
//----------------------------------------------------------------------------
int TVictorWideStringList::IndexOf(TVictorWideString ws)
{
int n = Count;
for(int i=0; i<n; i++)
{
if(Item[i] == ws)
return i;
}
return -1;
}
//----------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
__fastcall TAppLang::TAppLang()
{
_SysLangId = GetSystemDefaultLangID();
_bTransBig5 = true;
fSetDetectType(dtAuto);
}
//---------------------------------------------------------------------------
__fastcall TAppLang::~TAppLang()
{
//do nothing.
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::fSetCvtBig5(bool bCvt)
{
_bTransBig5 = bCvt;
}
//---------------------------------------------------------------------------
int __fastcall TAppLang::_fGBK_No(unsigned char qm, unsigned char wm)
{
int n = (qm-0x81)*191 + (wm-0x40);
return (n>=0 && n<GBK_COUNT)? n:0;
}
//---------------------------------------------------------------------------
TVictorString __fastcall TAppLang::FromGBK(TVictorString s)
{
if((_LangType == ltBig5) && (_bTransBig5))
{
AnsiString RetVal;
int i, n = s.Length();
char *Buf = new char[n+1];
char *Src = new char[n+1];
strcpy(Src,s);
for(i=0; i<n; i++)
{
if( ((unsigned char)Src[i] >= 0x81) && ((unsigned char)Src[i] <= 0xfe)
&& ((unsigned char)Src[i+1] >= 0x40) && ((unsigned char)Src[i+1] <= 0xfe) )
{
*((CHINESE_CHAR*)(Buf+i)) = GB2BIG5_TAB[_fGBK_No(Src[i],Src[i+1])];
*(Buf+i) ^= 0x80;
i++; //2 bytes / chinese-character
}
else
{
Buf[i] = Src[i];
}
}
Buf[i] = 0;
RetVal = Buf;
delete[] Src;
delete[] Buf;
return RetVal;
}
return s;
}
//---------------------------------------------------------------------------
TVictorString __fastcall TAppLang::fGetPdxLangDrv(void) //Get Paradox Language Driver from LangType
{
switch(_LangType)
{
case ltGbk : return Str_ParadoxGbk;
case ltBig5: return Str_ParadoxBig5;
default : return Str_ParadoxAscii;
}
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::fSetLangType(TLangType t)
{
_LangType = t; //t -> LangType
_DetectType = dtManual; //dtManual -> DetectType
_fCharsetFromLangType(); //LangType -> Charset
_fFontNameSizeFromLangType(); //LangType -> FontName & FontSize
}
void __fastcall TAppLang::fSetFontName(TVictorString s) //-> none
{
_FontName = s;
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::fSetCharset(TFontCharset c)
{
_Charset = c; //c -> Charset
_DetectType = dtManual; //dtManual -> DetectType
_fLangTypeFromCharset(); //Charset -> LangType
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::fSetFontSize(int i) //-> none
{
_FontSize = i;
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::fSetDetectType(TDetectType dtType)
{
_DetectType = dtType; //dtType -> DetectType
_fLangTypeFromDetectType(); //DetectType -> LangType
_fCharsetFromLangType(); //LangType -> Charset
_fFontNameSizeFromLangType(); //LangType -> FontName & FontSize
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::_fLangTypeFromCharset(void) //Charset -> LangType
{
switch(_Charset)
{
case GB2312_CHARSET : _LangType = ltGbk ; break;
case CHINESEBIG5_CHARSET: _LangType = ltBig5; break;
default : _LangType = ltAnsi; break;
}
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::_fLangTypeFromDetectType(void) //DetectType -> LangType
{
if(_DetectType != dtManual)
{
if(PRIMARYLANGID(_SysLangId) == LANG_CHINESE)
{
if((SUBLANGID(_SysLangId) == SUBLANG_CHINESE_SIMPLIFIED) //Mainland China & Singapore
||(SUBLANGID(_SysLangId) == SUBLANG_CHINESE_SINGAPORE)) //-- Simplified Chinese
{
_LangType = ltGbk;
}
else //Other Countries & Regiones -- Traditional Chinese
{
_LangType = ltBig5;
}
}
else //dtAuto -> ANSI
{
_LangType = ltAnsi;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::_fCharsetFromLangType(void) //LangType -> Charset
{
switch(_LangType)
{
case ltGbk : _Charset = GB2312_CHARSET ; break;
case ltBig5: _Charset = CHINESEBIG5_CHARSET; break;
default : _Charset = ANSI_CHARSET ; break;
}
}
//---------------------------------------------------------------------------
void __fastcall TAppLang::_fFontNameSizeFromLangType(void) //LangType -> FontName & FontSize
{
switch(_LangType)
{
case ltGbk :
#ifndef __CONSOLE__
if(Screen->Fonts->IndexOf(Str_SongTi)>=0)
_FontName = Str_SongTi;
else
_FontName = Str_SimSun;
#else
_FontName = Str_SongTi;
#endif
_FontSize = 9;
break;
case ltBig5:
#ifndef __CONSOLE__
if(Screen->Fonts->IndexOf(Str_XiMyTi)>=0)
_FontName = Str_XiMyTi;
else
_FontName = Str_MingLiU;
#else
_FontName = Str_XiMyTi;
#endif
_FontSize = 9;
break;
default : _FontName = Str_MsSansSerif;
_FontSize = 8;
break;
}
}
//---------------------------------------------------------------------------
int __fastcall TAppLang::_fGetMinFontSize(void)
{
switch(_LangType)
{
case ltGbk : return 9;
case ltBig5: return 9;
default : return 8;
}
}
//---------------------------------------------------------------------------
//=========================================================================//
// class DateX //
//=========================================================================//
const int DateX::_MonthDays[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
//---------------------------------------------------------------------------
void DateX::Assign(TDateTime x)
{
unsigned short y,m,d;
DecodeDate(x, y,m,d);
Assign(y,m,d);
}
void DateX::Assign(long Year, int Month, int Day)
{
_Year = Year;
_Month = Month;
_Day = Day;
DateToY111(); // _Year, _Month, _Day --> _Days111
AssignDOW(); // _Days111 --> _DOW
}
//--------------------------------------------------------------------------
void DateX::NextMonth(int m)
{
_Month+=m;
if(_Month>0)
{
_Year+=(_Month-1)/12;
_Month=((_Month-1)%12)+1;
}
else
{
_Year+=(_Month-12)/12;
_Month=(_Month%12)+12;
}
DateToY111(); // _Year, _Month, _Day --> _Days111
AssignDOW(); // _Days111 --> _DOW
}
//--------------------------------------------------------------------------
int DateX::GetMonthDays(int Month)
{
if((Month<1)||(Month>12)) return 0;
if((Month==2)&&(_isLeap())) return 29;
return _MonthDays[Month-1];
}
//--------------------------------------------------------------------------
void DateX::AssignDOW(void) // Day of Week
{
_DOW = (int) (_lDays111 % 7);
}
//--------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -