123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- // Variable.cpp: implementation of the CVariable class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "DataManager.h"
- #include "Variable.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- int nCount = 0;
- CVariable::CVariable()
- {
- nCount++;
- m_bCanRead = TRUE;
- m_bCanWrite = TRUE;
- m_bIsDesignTimeVar = FALSE;
- vt = VT_BSTR;
- }
- CVariable::~CVariable()
- {
- nCount--;
- }
- CString CVariable::GetTextValue()
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- return m_strTextValue;
- // CString strTxtValue;
- // switch (vt)
- // {
- // case VT_EMPTY:
- // case VT_NULL:
- // break;
- //
- // case VT_BOOL:
- // strTxtValue = boolVal?"True":"False";
- // break;
- // case VT_UI1:
- // strTxtValue.Format("%d", (int)bVal);
- // break;
- // case VT_I2:
- // strTxtValue.Format("%d", (int)iVal);
- // break;
- // case VT_I4:
- // strTxtValue.Format("%d", lVal);
- // break;
- // case VT_R4:
- // //strTxtValue.Format("%g", fltVal);
- // strTxtValue = GetDoubleText(double(fltVal));
- // break;
- // case VT_R8:
- // case VT_I8:
- // case VT_UI8:
- // //strTxtValue.Format("%g", dblVal);
- // strTxtValue = GetDoubleText(dblVal);
- // break;
- // case VT_I1:
- // strTxtValue.Format("%d", (int)cVal);
- // break;
- // case VT_UI2:
- // strTxtValue.Format("%u", (int)uiVal);
- // break;
- // case VT_UI4:
- // strTxtValue.Format("%u", ulVal);
- // break;
- // case VT_DATE:
- // strTxtValue.Format("%g", date);
- // break;
- // case VT_BSTR:
- // if(bstrVal != NULL)
- // strTxtValue = bstrVal;
- // else
- // strTxtValue = m_strTextValue;
- // break;
- //
- // case VT_ERROR:
- // strTxtValue.Format("%d", scode);
- // break;
- //
- // default:
- // break;
- // }
- // m_strTextValue = strTxtValue;
- // return m_strTextValue;
- }
- void CVariable::SetTextValue(CString strTextValue, VARTYPE vtSrc)
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- int nPos = strTextValue.Find("|::FMT:");
- if(nPos != -1)
- m_strTextValue = strTextValue.Left(nPos);
- else
- m_strTextValue = strTextValue;
- // try
- // {
- // //m_strTextValue = strTextValue;
- // if(vtSrc == VT_EMPTY)
- // vtSrc = VT_BSTR;
- // vt = vtSrc;
- // SetSaveFmtTxt(strTextValue);
- //
- // CString strTxtValue = m_strTextValue;
- // switch (vt)
- // {
- // case VT_EMPTY:
- // case VT_NULL:
- // break;
- //
- // case VT_BOOL:
- // strTxtValue.MakeUpper();
- // boolVal = (strTextValue == "TRUE");
- // break;
- // case VT_UI1:
- // bVal = atoi(m_strTextValue);
- // break;
- // case VT_I2:
- // iVal = atoi(m_strTextValue);
- // break;
- // case VT_I4:
- // lVal = atoi(m_strTextValue);
- // break;
- // case VT_R4:
- // fltVal = (float)atof(m_strTextValue);
- // break;
- // case VT_R8:
- // case VT_I8:
- // case VT_UI8:
- // dblVal = atof(m_strTextValue);
- // break;
- // case VT_I1:
- // cVal = atoi(m_strTextValue);
- // break;
- // case VT_UI2:
- // uiVal = atoi(m_strTextValue);
- // break;
- // case VT_UI4:
- // ulVal = atoi(m_strTextValue);
- // break;
- // case VT_DATE:
- // date = atof(m_strTextValue);
- // break;
- // case VT_BSTR:
- // *((COleVariant*)this) = m_strTextValue;
- // break;
- //
- // case VT_ERROR:
- // scode = atoi(m_strTextValue);
- // break;
- //
- // default:
- // break;
- // }
- // }
- // catch(...)
- // {
- // TRACE("Error Happened while operator = executed!\n");
- // }
- }
- CString CVariable::GetSaveFmtTxt()
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- // CString strFmtValue;
- m_strTextValue.Replace("\r\n", ";");
- // strFmtValue.Format("%s|::FMT:DTV:%d,R:%d,W:%d,VT:%d,", m_strTextValue, m_bIsDesignTimeVar, m_bCanRead, m_bCanWrite, vt);
- return m_strTextValue;
- }
- void CVariable::SetSaveFmtTxt(CString strSaveFmtTxt)
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- m_strTextValue = strSaveFmtTxt;
- int nPos = strSaveFmtTxt.Find("|::FMT:");
- if(nPos != -1)
- {
- m_strTextValue = strSaveFmtTxt.Left(nPos);
- // CString strFmt = strSaveFmtTxt.Mid(nPos+7);
- // nPos = strFmt.Find("DTV:");
- // if(nPos > -1)
- // m_bIsDesignTimeVar = atoi(strFmt.Mid(nPos+4));
- // nPos = strFmt.Find("R:");
- // if(nPos > -1)
- // m_bCanRead = atoi(strFmt.Mid(nPos+2));
- // nPos = strFmt.Find("W:");
- // if(nPos > -1)
- // m_bCanWrite = atoi(strFmt.Mid(nPos+2));
- // vt = VT_BSTR;
- // nPos = strFmt.Find("VT:");
- // if(nPos > -1)
- // vt = (VARTYPE)atoi(strFmt.Mid(nPos+3));
- // SetTextValue(m_strTextValue, vt);
- }
- }
- VARTYPE CVariable::GetVarType()
- {
- return vt;
- }
- CString CVariable::GetTypeName(VARTYPE vt)
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- static CString strTypes[73];
- if(strTypes[VT_EMPTY] == "")
- {
- strTypes[VT_EMPTY] = "VT_EMPTY";
- strTypes[VT_NULL] = "VT_NULL";
- strTypes[VT_I2] = "VT_I2";
- strTypes[VT_I4] = "VT_I4";
- strTypes[VT_R4] = "VT_R4";
- strTypes[VT_R8] = "VT_R8";
- strTypes[VT_CY] = "VT_CY";
- strTypes[VT_DATE] = "VT_DATE";
- strTypes[VT_BSTR] = "VT_BSTR";
- strTypes[VT_DISPATCH] = "VT_DISPATCH";
- strTypes[VT_ERROR] = "VT_ERROR";
- strTypes[VT_BOOL] = "VT_BOOL";
- strTypes[VT_VARIANT] = "VT_VARIANT";
- strTypes[VT_UNKNOWN] = "VT_UNKNOWN";
- strTypes[VT_DECIMAL] = "VT_DECIMAL";
- // VBA reserves 15 for future use
- strTypes[VT_I1] = "VT_I1";
- strTypes[VT_UI1] = "VT_UI1";
- strTypes[VT_UI2] = "VT_UI2";
- strTypes[VT_UI4] = "VT_UI4";
- strTypes[VT_I8] = "VT_I8";
- strTypes[VT_UI8] = "VT_UI8";
- strTypes[VT_INT] = "VT_INT";
- strTypes[VT_UINT] = "VT_UINT";
- strTypes[VT_VOID] = "VT_VOID";
- strTypes[VT_HRESULT] = "VT_HRESULT";
- strTypes[VT_PTR] = "VT_PTR";
- strTypes[VT_SAFEARRAY] = "VT_SAFEARRAY";
- strTypes[VT_CARRAY] = "VT_CARRAY";
- strTypes[VT_USERDEFINED] = "VT_USERDEFINED";
- strTypes[VT_LPSTR] = "VT_LPSTR";
- strTypes[VT_LPWSTR] = "VT_LPWSTR";
- // VBA reserves 32-35 for future use
- "",
- strTypes[VT_FILETIME] = "VT_FILETIME";
- strTypes[VT_BLOB] = "VT_BLOB";
- strTypes[VT_STREAM] = "VT_STREAM";
- strTypes[VT_STORAGE] = "VT_STORAGE";
- strTypes[VT_STREAMED_OBJECT] = "VT_STREAMED_OBJECT";
- strTypes[VT_STORED_OBJECT] = "VT_STORED_OBJECT";
- strTypes[VT_BLOB_OBJECT] = "VT_BLOB_OBJECT";
- strTypes[VT_CF] = "VT_CF";
- strTypes[VT_CLSID] = "VT_CLSID";
- }
- if(vt >= 73)
- vt = VT_EMPTY;
- return strTypes[vt];
- }
- // »ñÈ¡ÌØÐÔ
- CString CVariable::GetAttributesMsg()
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- CString strAttr;
- strAttr.Format("DTV:%d,R:%d,W:%d,VT:%s,", m_bIsDesignTimeVar, m_bCanRead, m_bCanWrite, GetTypeName(vt));
- return strAttr;
- }
- // ÉèÖÃÌØÐÔ
- void CVariable::SetAttributes(BOOL bIsDesignTimeVar, BOOL bCanRead, BOOL bCanWrite, VARTYPE vtSrc)
- {
- // AFX_MANAGE_STATE(AfxGetStaticModuleState());
- m_bIsDesignTimeVar = bIsDesignTimeVar;
- m_bCanRead = bCanRead;
- m_bCanWrite = bCanWrite;
- vt = vtSrc;
- }
- CVariable& CVariable::operator = (COleVariant & var)
- {
- *((COleVariant*)this) = var;
- return *this;
- }
|