Variable.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. // Variable.cpp: implementation of the CVariable class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "DataManager.h"
  6. #include "Variable.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. int nCount = 0;
  16. CVariable::CVariable()
  17. {
  18. nCount++;
  19. m_bCanRead = TRUE;
  20. m_bCanWrite = TRUE;
  21. m_bIsDesignTimeVar = FALSE;
  22. vt = VT_BSTR;
  23. }
  24. CVariable::~CVariable()
  25. {
  26. nCount--;
  27. }
  28. CString CVariable::GetTextValue()
  29. {
  30. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  31. return m_strTextValue;
  32. // CString strTxtValue;
  33. // switch (vt)
  34. // {
  35. // case VT_EMPTY:
  36. // case VT_NULL:
  37. // break;
  38. //
  39. // case VT_BOOL:
  40. // strTxtValue = boolVal?"True":"False";
  41. // break;
  42. // case VT_UI1:
  43. // strTxtValue.Format("%d", (int)bVal);
  44. // break;
  45. // case VT_I2:
  46. // strTxtValue.Format("%d", (int)iVal);
  47. // break;
  48. // case VT_I4:
  49. // strTxtValue.Format("%d", lVal);
  50. // break;
  51. // case VT_R4:
  52. // //strTxtValue.Format("%g", fltVal);
  53. // strTxtValue = GetDoubleText(double(fltVal));
  54. // break;
  55. // case VT_R8:
  56. // case VT_I8:
  57. // case VT_UI8:
  58. // //strTxtValue.Format("%g", dblVal);
  59. // strTxtValue = GetDoubleText(dblVal);
  60. // break;
  61. // case VT_I1:
  62. // strTxtValue.Format("%d", (int)cVal);
  63. // break;
  64. // case VT_UI2:
  65. // strTxtValue.Format("%u", (int)uiVal);
  66. // break;
  67. // case VT_UI4:
  68. // strTxtValue.Format("%u", ulVal);
  69. // break;
  70. // case VT_DATE:
  71. // strTxtValue.Format("%g", date);
  72. // break;
  73. // case VT_BSTR:
  74. // if(bstrVal != NULL)
  75. // strTxtValue = bstrVal;
  76. // else
  77. // strTxtValue = m_strTextValue;
  78. // break;
  79. //
  80. // case VT_ERROR:
  81. // strTxtValue.Format("%d", scode);
  82. // break;
  83. //
  84. // default:
  85. // break;
  86. // }
  87. // m_strTextValue = strTxtValue;
  88. // return m_strTextValue;
  89. }
  90. void CVariable::SetTextValue(CString strTextValue, VARTYPE vtSrc)
  91. {
  92. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  93. int nPos = strTextValue.Find("|::FMT:");
  94. if(nPos != -1)
  95. m_strTextValue = strTextValue.Left(nPos);
  96. else
  97. m_strTextValue = strTextValue;
  98. // try
  99. // {
  100. // //m_strTextValue = strTextValue;
  101. // if(vtSrc == VT_EMPTY)
  102. // vtSrc = VT_BSTR;
  103. // vt = vtSrc;
  104. // SetSaveFmtTxt(strTextValue);
  105. //
  106. // CString strTxtValue = m_strTextValue;
  107. // switch (vt)
  108. // {
  109. // case VT_EMPTY:
  110. // case VT_NULL:
  111. // break;
  112. //
  113. // case VT_BOOL:
  114. // strTxtValue.MakeUpper();
  115. // boolVal = (strTextValue == "TRUE");
  116. // break;
  117. // case VT_UI1:
  118. // bVal = atoi(m_strTextValue);
  119. // break;
  120. // case VT_I2:
  121. // iVal = atoi(m_strTextValue);
  122. // break;
  123. // case VT_I4:
  124. // lVal = atoi(m_strTextValue);
  125. // break;
  126. // case VT_R4:
  127. // fltVal = (float)atof(m_strTextValue);
  128. // break;
  129. // case VT_R8:
  130. // case VT_I8:
  131. // case VT_UI8:
  132. // dblVal = atof(m_strTextValue);
  133. // break;
  134. // case VT_I1:
  135. // cVal = atoi(m_strTextValue);
  136. // break;
  137. // case VT_UI2:
  138. // uiVal = atoi(m_strTextValue);
  139. // break;
  140. // case VT_UI4:
  141. // ulVal = atoi(m_strTextValue);
  142. // break;
  143. // case VT_DATE:
  144. // date = atof(m_strTextValue);
  145. // break;
  146. // case VT_BSTR:
  147. // *((COleVariant*)this) = m_strTextValue;
  148. // break;
  149. //
  150. // case VT_ERROR:
  151. // scode = atoi(m_strTextValue);
  152. // break;
  153. //
  154. // default:
  155. // break;
  156. // }
  157. // }
  158. // catch(...)
  159. // {
  160. // TRACE("Error Happened while operator = executed!\n");
  161. // }
  162. }
  163. CString CVariable::GetSaveFmtTxt()
  164. {
  165. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  166. // CString strFmtValue;
  167. m_strTextValue.Replace("\r\n", ";");
  168. // strFmtValue.Format("%s|::FMT:DTV:%d,R:%d,W:%d,VT:%d,", m_strTextValue, m_bIsDesignTimeVar, m_bCanRead, m_bCanWrite, vt);
  169. return m_strTextValue;
  170. }
  171. void CVariable::SetSaveFmtTxt(CString strSaveFmtTxt)
  172. {
  173. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  174. m_strTextValue = strSaveFmtTxt;
  175. int nPos = strSaveFmtTxt.Find("|::FMT:");
  176. if(nPos != -1)
  177. {
  178. m_strTextValue = strSaveFmtTxt.Left(nPos);
  179. // CString strFmt = strSaveFmtTxt.Mid(nPos+7);
  180. // nPos = strFmt.Find("DTV:");
  181. // if(nPos > -1)
  182. // m_bIsDesignTimeVar = atoi(strFmt.Mid(nPos+4));
  183. // nPos = strFmt.Find("R:");
  184. // if(nPos > -1)
  185. // m_bCanRead = atoi(strFmt.Mid(nPos+2));
  186. // nPos = strFmt.Find("W:");
  187. // if(nPos > -1)
  188. // m_bCanWrite = atoi(strFmt.Mid(nPos+2));
  189. // vt = VT_BSTR;
  190. // nPos = strFmt.Find("VT:");
  191. // if(nPos > -1)
  192. // vt = (VARTYPE)atoi(strFmt.Mid(nPos+3));
  193. // SetTextValue(m_strTextValue, vt);
  194. }
  195. }
  196. VARTYPE CVariable::GetVarType()
  197. {
  198. return vt;
  199. }
  200. CString CVariable::GetTypeName(VARTYPE vt)
  201. {
  202. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  203. static CString strTypes[73];
  204. if(strTypes[VT_EMPTY] == "")
  205. {
  206. strTypes[VT_EMPTY] = "VT_EMPTY";
  207. strTypes[VT_NULL] = "VT_NULL";
  208. strTypes[VT_I2] = "VT_I2";
  209. strTypes[VT_I4] = "VT_I4";
  210. strTypes[VT_R4] = "VT_R4";
  211. strTypes[VT_R8] = "VT_R8";
  212. strTypes[VT_CY] = "VT_CY";
  213. strTypes[VT_DATE] = "VT_DATE";
  214. strTypes[VT_BSTR] = "VT_BSTR";
  215. strTypes[VT_DISPATCH] = "VT_DISPATCH";
  216. strTypes[VT_ERROR] = "VT_ERROR";
  217. strTypes[VT_BOOL] = "VT_BOOL";
  218. strTypes[VT_VARIANT] = "VT_VARIANT";
  219. strTypes[VT_UNKNOWN] = "VT_UNKNOWN";
  220. strTypes[VT_DECIMAL] = "VT_DECIMAL";
  221. // VBA reserves 15 for future use
  222. strTypes[VT_I1] = "VT_I1";
  223. strTypes[VT_UI1] = "VT_UI1";
  224. strTypes[VT_UI2] = "VT_UI2";
  225. strTypes[VT_UI4] = "VT_UI4";
  226. strTypes[VT_I8] = "VT_I8";
  227. strTypes[VT_UI8] = "VT_UI8";
  228. strTypes[VT_INT] = "VT_INT";
  229. strTypes[VT_UINT] = "VT_UINT";
  230. strTypes[VT_VOID] = "VT_VOID";
  231. strTypes[VT_HRESULT] = "VT_HRESULT";
  232. strTypes[VT_PTR] = "VT_PTR";
  233. strTypes[VT_SAFEARRAY] = "VT_SAFEARRAY";
  234. strTypes[VT_CARRAY] = "VT_CARRAY";
  235. strTypes[VT_USERDEFINED] = "VT_USERDEFINED";
  236. strTypes[VT_LPSTR] = "VT_LPSTR";
  237. strTypes[VT_LPWSTR] = "VT_LPWSTR";
  238. // VBA reserves 32-35 for future use
  239. "",
  240. strTypes[VT_FILETIME] = "VT_FILETIME";
  241. strTypes[VT_BLOB] = "VT_BLOB";
  242. strTypes[VT_STREAM] = "VT_STREAM";
  243. strTypes[VT_STORAGE] = "VT_STORAGE";
  244. strTypes[VT_STREAMED_OBJECT] = "VT_STREAMED_OBJECT";
  245. strTypes[VT_STORED_OBJECT] = "VT_STORED_OBJECT";
  246. strTypes[VT_BLOB_OBJECT] = "VT_BLOB_OBJECT";
  247. strTypes[VT_CF] = "VT_CF";
  248. strTypes[VT_CLSID] = "VT_CLSID";
  249. }
  250. if(vt >= 73)
  251. vt = VT_EMPTY;
  252. return strTypes[vt];
  253. }
  254. // »ñÈ¡ÌØÐÔ
  255. CString CVariable::GetAttributesMsg()
  256. {
  257. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  258. CString strAttr;
  259. strAttr.Format("DTV:%d,R:%d,W:%d,VT:%s,", m_bIsDesignTimeVar, m_bCanRead, m_bCanWrite, GetTypeName(vt));
  260. return strAttr;
  261. }
  262. // ÉèÖÃÌØÐÔ
  263. void CVariable::SetAttributes(BOOL bIsDesignTimeVar, BOOL bCanRead, BOOL bCanWrite, VARTYPE vtSrc)
  264. {
  265. // AFX_MANAGE_STATE(AfxGetStaticModuleState());
  266. m_bIsDesignTimeVar = bIsDesignTimeVar;
  267. m_bCanRead = bCanRead;
  268. m_bCanWrite = bCanWrite;
  269. vt = vtSrc;
  270. }
  271. CVariable& CVariable::operator = (COleVariant & var)
  272. {
  273. *((COleVariant*)this) = var;
  274. return *this;
  275. }