cvarutil.inc 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2000,2001 by the Free Pascal development team
  4. Interface and OS-dependent part of variant support
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. Procedure VariantTypeMismatch; overload;
  12. begin
  13. Raise EVariantError.CreateCode(VAR_TYPEMISMATCH);
  14. end;
  15. Procedure VariantTypeMismatch(const SourceType, DestType: TVarType);
  16. begin
  17. { ignore the types for now ... }
  18. Raise EVariantError.CreateCode(VAR_TYPEMISMATCH);
  19. end;
  20. Function ExceptionToVariantError (E : Exception): HResult;
  21. begin
  22. If E is EoutOfMemory then
  23. Result:=VAR_OUTOFMEMORY
  24. else
  25. Result:=VAR_EXCEPTION;
  26. end;
  27. { ---------------------------------------------------------------------
  28. OS-independent functions not present in Windows
  29. ---------------------------------------------------------------------}
  30. {--- SmallInt ---}
  31. Function WStrToSmallInt(p: Pointer) : SmallInt;
  32. var
  33. Error : Word;
  34. begin
  35. Val(WideString(p), Result, Error);
  36. if Error <> 0 then
  37. VariantTypeMismatch(varOleStr, varSmallInt);
  38. end;
  39. Function LStrToSmallInt(p: Pointer) : SmallInt;
  40. var
  41. Error : Word;
  42. begin
  43. Val(AnsiString(p), Result, Error);
  44. if Error <> 0 then
  45. VariantTypeMismatch(varString, varSmallInt);
  46. end;
  47. function UStrToSmallInt(p: Pointer): SmallInt;
  48. var
  49. Error: Word;
  50. begin
  51. Val(UnicodeString(p), Result, Error);
  52. if Error <> 0 then
  53. VariantTypeMismatch(varUString, varSmallInt);
  54. end;
  55. Function VariantToSmallInt(const VargSrc : TVarData) : SmallInt;
  56. begin
  57. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  58. DumpVariant('VariantToSmallInt', VargSrc);
  59. end; {$ENDIF}
  60. with VargSrc do
  61. case vType and not varTypeMask of
  62. 0: case vType of
  63. varEmpty : Result := 0;
  64. varSmallInt : Result := vSmallInt;
  65. varShortInt : Result := vShortInt;
  66. varInteger : Result := smallint(vInteger);
  67. {$ifndef FPUNONE}
  68. varSingle : Result := smallint(Round(vSingle));
  69. varDouble : Result := smallint(Round(vDouble));
  70. varDate : Result := smallint(Round(vDate));
  71. {$endif}
  72. varCurrency : Result := smallint(Round(vCurrency));
  73. varBoolean : Result := smallint(SmallInt(vBoolean));
  74. varVariant : Result := VariantToSmallInt(PVarData(vPointer)^);
  75. varByte : Result := vByte;
  76. varWord : Result := smallint(vWord);
  77. varLongWord : Result := smallint(vLongWord);
  78. varInt64 : Result := smallint(vInt64);
  79. varQword : Result := smallint(vQWord);
  80. varOleStr : Result := WStrToSmallInt(vOleStr);
  81. varString : Result := LStrToSmallInt(vString);
  82. varUString : Result := UStrToSmallInt(vString);
  83. else
  84. VariantTypeMismatch(vType, varSmallInt);
  85. end;
  86. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  87. varSmallInt : Result := PSmallInt(vPointer)^;
  88. varShortInt : Result := PShortInt(vPointer)^;
  89. varInteger : Result := smallint(PInteger(vPointer)^);
  90. {$ifndef FPUNONE}
  91. varSingle : Result := smallint(Round(PSingle(vPointer)^));
  92. varDouble : Result := smallint(Round(PDouble(vPointer)^));
  93. varDate : Result := smallint(Round(PDate(vPointer)^));
  94. {$endif}
  95. varCurrency : Result := smallint(Round(PCurrency(vPointer)^));
  96. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  97. varVariant : Result := VariantToSmallInt(PVarData(vPointer)^);
  98. varByte : Result := PByte(vPointer)^;
  99. varWord : Result := smallint(PWord(vPointer)^);
  100. varLongWord : Result := smallint(PLongWord(vPointer)^);
  101. varInt64 : Result := smallint(PInt64(vPointer)^);
  102. varQword : Result := smallint(PQWord(vPointer)^);
  103. varOleStr : Result := WStrToSmallInt(PPointer(vPointer)^);
  104. varString : Result := LStrToSmallInt(PPointer(vPointer)^);
  105. varUString : Result := UStrToSmallInt(PPointer(vPointer)^);
  106. else { other vtype }
  107. VariantTypeMismatch(vType, varSmallInt);
  108. end else { pointer is nil }
  109. VariantTypeMismatch(vType, varSmallInt);
  110. else { array or something like that }
  111. VariantTypeMismatch(vType, varSmallInt);
  112. end;
  113. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  114. WriteLn('VariantToSmallInt -> ', Result);
  115. end; {$ENDIF}
  116. end;
  117. {--- ShortInt ---}
  118. Function WStrToShortInt(p: Pointer) : ShortInt;
  119. var
  120. Error : Word;
  121. begin
  122. Val(WideString(p), Result, Error);
  123. if Error <> 0 then
  124. VariantTypeMismatch(varOleStr, varShortInt);
  125. end;
  126. Function LStrToShortInt(p: Pointer) : ShortInt;
  127. var
  128. Error : Word;
  129. begin
  130. Val(AnsiString(p), Result, Error);
  131. if Error <> 0 then
  132. VariantTypeMismatch(varString, varShortInt);
  133. end;
  134. Function UStrToShortInt(p: Pointer) : ShortInt;
  135. var
  136. Error : Word;
  137. begin
  138. Val(UnicodeString(p), Result, Error);
  139. if Error <> 0 then
  140. VariantTypeMismatch(varUString, varShortInt);
  141. end;
  142. Function VariantToShortInt(const VargSrc : TVarData) : ShortInt;
  143. begin
  144. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  145. DumpVariant('VariantToShortInt', VargSrc);
  146. end; {$ENDIF}
  147. with VargSrc do
  148. case vType and not varTypeMask of
  149. 0: case vType of
  150. varEmpty : Result := 0;
  151. varSmallInt : Result := shortint(vSmallInt);
  152. varShortInt : Result := vShortInt;
  153. varInteger : Result := shortint(vInteger);
  154. {$ifndef FPUNONE}
  155. varSingle : Result := shortint(Round(vSingle));
  156. varDouble : Result := shortint(Round(vDouble));
  157. varDate : Result := shortint(Round(vDate));
  158. {$endif}
  159. varCurrency : Result := shortint(Round(vCurrency));
  160. varBoolean : Result := shortint(vBoolean);
  161. varVariant : Result := VariantToShortInt(PVarData(vPointer)^);
  162. varByte : Result := shortint(vByte);
  163. varWord : Result := shortint(vWord);
  164. varLongWord : Result := shortint(vLongWord);
  165. varInt64 : Result := shortint(vInt64);
  166. varQword : Result := shortint(vQWord);
  167. varOleStr : Result := WStrToShortInt(vOleStr);
  168. varString : Result := LStrToShortInt(vString);
  169. varUString : Result := UStrToShortInt(vString);
  170. else
  171. VariantTypeMismatch(vType, varShortInt);
  172. end;
  173. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  174. varSmallInt : Result := shortint(PSmallInt(vPointer)^);
  175. varShortInt : Result := PShortInt(vPointer)^;
  176. varInteger : Result := shortint(PInteger(vPointer)^);
  177. {$ifndef FPUNONE}
  178. varSingle : Result := shortint(Round(PSingle(vPointer)^));
  179. varDouble : Result := shortint(Round(PDouble(vPointer)^));
  180. varDate : Result := shortint(Round(PDate(vPointer)^));
  181. {$endif}
  182. varCurrency : Result := shortint(Round(PCurrency(vPointer)^));
  183. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  184. varVariant : Result := VariantToShortInt(PVarData(vPointer)^);
  185. varByte : Result := shortint(PByte(vPointer)^);
  186. varWord : Result := shortint(PWord(vPointer)^);
  187. varLongWord : Result := shortint(PLongWord(vPointer)^);
  188. varInt64 : Result := shortint(PInt64(vPointer)^);
  189. varQword : Result := shortint(PQWord(vPointer)^);
  190. varOleStr : Result := WStrToShortInt(PPointer(vPointer)^);
  191. varString : Result := LStrToShortInt(PPointer(vPointer)^);
  192. varUString : Result := UStrToShortInt(PPointer(vPointer)^);
  193. else { other vtype }
  194. VariantTypeMismatch(vType, varShortInt);
  195. end else { pointer is nil }
  196. VariantTypeMismatch(vType, varShortInt);
  197. else { array or something like that }
  198. VariantTypeMismatch(vType, varShortInt);
  199. end;
  200. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  201. WriteLn('VariantToShortInt -> ', Result);
  202. end; {$ENDIF}
  203. end;
  204. {--- LongInt ---}
  205. Function WStrToLongInt(p: Pointer) : LongInt;
  206. var
  207. Error : Word;
  208. begin
  209. Val(WideString(p), Result, Error);
  210. if Error <> 0 then
  211. VariantTypeMismatch(varOleStr, varInteger);
  212. end;
  213. Function LStrToLongInt(p: Pointer) : LongInt;
  214. var
  215. Error : Word;
  216. begin
  217. Val(AnsiString(p), Result, Error);
  218. if Error <> 0 then
  219. VariantTypeMismatch(varString, varInteger);
  220. end;
  221. Function UStrToLongInt(p: Pointer) : LongInt;
  222. var
  223. Error : Word;
  224. begin
  225. Val(UnicodeString(p), Result, Error);
  226. if Error <> 0 then
  227. VariantTypeMismatch(varUString, varInteger);
  228. end;
  229. Function VariantToLongInt(const VargSrc : TVarData) : LongInt;
  230. begin
  231. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  232. DumpVariant('VariantToLongInt', VargSrc);
  233. end; {$ENDIF}
  234. with VargSrc do
  235. case vType and not varTypeMask of
  236. 0: case vType of
  237. varEmpty : Result := 0;
  238. varSmallInt : Result := vSmallInt;
  239. varShortInt : Result := vShortInt;
  240. varInteger : Result := vInteger;
  241. {$ifndef FPUNONE}
  242. varSingle : Result := longint(Round(vSingle));
  243. varDouble : Result := longint(Round(vDouble));
  244. varDate : Result := longint(Round(vDate));
  245. {$endif}
  246. varCurrency : Result := longint(Round(vCurrency));
  247. varBoolean : Result := SmallInt(vBoolean);
  248. varVariant : Result := VariantToLongInt(PVarData(vPointer)^);
  249. varByte : Result := vByte;
  250. varWord : Result := vWord;
  251. varLongWord : Result := longint(vLongWord);
  252. varInt64 : Result := longint(vInt64);
  253. varQword : Result := longint(vQWord);
  254. varOleStr : Result := WStrToLongInt(vOleStr);
  255. varString : Result := LStrToLongInt(vString);
  256. varUString : Result := UStrToLongInt(vString);
  257. else
  258. VariantTypeMismatch(vType, varInteger);
  259. end;
  260. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  261. varSmallInt : Result := PSmallInt(vPointer)^;
  262. varShortInt : Result := PShortInt(vPointer)^;
  263. varInteger : Result := PInteger(vPointer)^;
  264. {$ifndef FPUNONE}
  265. varSingle : Result := longint(Round(PSingle(vPointer)^));
  266. varDouble : Result := longint(Round(PDouble(vPointer)^));
  267. varDate : Result := longint(Round(PDate(vPointer)^));
  268. {$endif}
  269. varCurrency : Result := longint(Round(PCurrency(vPointer)^));
  270. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  271. varVariant : Result := VariantToLongInt(PVarData(vPointer)^);
  272. varByte : Result := PByte(vPointer)^;
  273. varWord : Result := PWord(vPointer)^;
  274. varLongWord : Result := longint(PLongWord(vPointer)^);
  275. varInt64 : Result := longint(PInt64(vPointer)^);
  276. varQword : Result := longint(PQWord(vPointer)^);
  277. varOleStr : Result := WStrToLongInt(PPointer(vPointer)^);
  278. varString : Result := LStrToLongInt(PPointer(vPointer)^);
  279. varUString : Result := UStrToLongInt(PPointer(vPointer)^);
  280. else { other vtype }
  281. VariantTypeMismatch(vType, varInteger);
  282. end else { pointer is nil }
  283. VariantTypeMismatch(vType, varInteger);
  284. else { array or something like that }
  285. VariantTypeMismatch(vType, varInteger);
  286. end;
  287. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  288. WriteLn('VariantToLongInt -> ', Result);
  289. end; {$ENDIF}
  290. end;
  291. {--- Cardinal ---}
  292. Function WStrToCardinal(p: Pointer) : Cardinal;
  293. var
  294. Error : Word;
  295. begin
  296. Val(WideString(p), Result, Error);
  297. if Error <> 0 then
  298. VariantTypeMismatch(varOleStr, varLongWord);
  299. end;
  300. Function LStrToCardinal(p: Pointer) : Cardinal;
  301. var
  302. Error : Word;
  303. begin
  304. Val(AnsiString(p), Result, Error);
  305. if Error <> 0 then
  306. VariantTypeMismatch(varString, varLongWord);
  307. end;
  308. Function UStrToCardinal(p: Pointer) : Cardinal;
  309. var
  310. Error : Word;
  311. begin
  312. Val(UnicodeString(p), Result, Error);
  313. if Error <> 0 then
  314. VariantTypeMismatch(varUString, varLongWord);
  315. end;
  316. Function VariantToCardinal(const VargSrc : TVarData) : Cardinal;
  317. begin
  318. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  319. DumpVariant('VariantToCardinal', VargSrc);
  320. end; {$ENDIF}
  321. with VargSrc do
  322. case vType and not varTypeMask of
  323. 0: case vType of
  324. varEmpty : Result := 0;
  325. varSmallInt : Result := vSmallInt;
  326. varShortInt : Result := vShortInt;
  327. varInteger : Result := cardinal(vInteger);
  328. {$ifndef FPUNONE}
  329. varSingle : Result := cardinal(Round(vSingle));
  330. varDouble : Result := cardinal(Round(vDouble));
  331. varDate : Result := cardinal(Round(vDate));
  332. {$endif}
  333. varCurrency : Result := cardinal(Round(vCurrency));
  334. varBoolean : Result := cardinal(SmallInt(vBoolean));
  335. varVariant : Result := VariantToCardinal(PVarData(vPointer)^);
  336. varByte : Result := vByte;
  337. varWord : Result := vWord;
  338. varLongWord : Result := vLongWord;
  339. varInt64 : Result := cardinal(vInt64);
  340. varQword : Result := cardinal(vQWord);
  341. varOleStr : Result := WStrToCardinal(vOleStr);
  342. varString : Result := LStrToCardinal(vString);
  343. varUString : Result := UStrToCardinal(vString);
  344. else
  345. VariantTypeMismatch(vType, varLongWord);
  346. end;
  347. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  348. varSmallInt : Result := cardinal(PSmallInt(vPointer)^);
  349. varShortInt : Result := cardinal(PShortInt(vPointer)^);
  350. varInteger : Result := cardinal(PInteger(vPointer)^);
  351. {$ifndef FPUNONE}
  352. varSingle : Result := cardinal(Round(PSingle(vPointer)^));
  353. varDouble : Result := cardinal(Round(PDouble(vPointer)^));
  354. varDate : Result := cardinal(Round(PDate(vPointer)^));
  355. {$endif}
  356. varCurrency : Result := cardinal(Round(PCurrency(vPointer)^));
  357. varBoolean : Result := cardinal(SmallInt(PWordBool(vPointer)^));
  358. varVariant : Result := VariantToCardinal(PVarData(vPointer)^);
  359. varByte : Result := PByte(vPointer)^;
  360. varWord : Result := PWord(vPointer)^;
  361. varLongWord : Result := PLongWord(vPointer)^;
  362. varInt64 : Result := cardinal(PInt64(vPointer)^);
  363. varQword : Result := cardinal(PQWord(vPointer)^);
  364. varOleStr : Result := WStrToCardinal(PPointer(vPointer)^);
  365. varString : Result := LStrToCardinal(PPointer(vPointer)^);
  366. varUString : Result := UStrToCardinal(PPointer(vPointer)^);
  367. else { other vtype }
  368. VariantTypeMismatch(vType, varLongWord);
  369. end else { pointer is nil }
  370. VariantTypeMismatch(vType, varLongWord);
  371. else { array or something like that }
  372. VariantTypeMismatch(vType, varLongWord);
  373. end;
  374. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  375. WriteLn('VariantToCardinal -> ', Result);
  376. end; {$ENDIF}
  377. end;
  378. procedure PrepareFloatStr(var s: ShortString);
  379. var
  380. i, j : Byte;
  381. begin
  382. j := 1;
  383. for i := 1 to Length(s) do
  384. if s[i] <> DefaultFormatSettings.ThousandSeparator then begin
  385. if s[i] = DefaultFormatSettings.DecimalSeparator then
  386. s[j] := '.'
  387. else
  388. s[j] := s[i];
  389. Inc(j);
  390. end;
  391. SetLength(s, Pred(j));
  392. end;
  393. {--- Single ---}
  394. {$ifndef FPUNONE}
  395. Function WStrToSingle(p: Pointer) : Single;
  396. var
  397. s : ShortString;
  398. Error : Word;
  399. begin
  400. if Length(WideString(p)) > 255 then
  401. VariantTypeMismatch(varOleStr, varSingle);
  402. s := WideString(p);
  403. PrepareFloatStr(s);
  404. Val(s, Result, Error);
  405. if Error <> 0 then
  406. VariantTypeMismatch(varOleStr, varSingle);
  407. end;
  408. Function LStrToSingle(p: Pointer) : Single;
  409. var
  410. s : ShortString;
  411. Error : Word;
  412. begin
  413. if Length(AnsiString(p)) > 255 then
  414. VariantTypeMismatch(varString, varSingle);
  415. s := AnsiString(p);
  416. PrepareFloatStr(s);
  417. Val(s, Result, Error);
  418. if Error <> 0 then
  419. VariantTypeMismatch(varString, varSingle);
  420. end;
  421. Function UStrToSingle(p: Pointer) : Single;
  422. var
  423. s : ShortString;
  424. Error : Word;
  425. begin
  426. if Length(UnicodeString(p)) > 255 then
  427. VariantTypeMismatch(varUString, varSingle);
  428. s := UnicodeString(p);
  429. PrepareFloatStr(s);
  430. Val(s, Result, Error);
  431. if Error <> 0 then
  432. VariantTypeMismatch(varUString, varSingle);
  433. end;
  434. Function VariantToSingle(const VargSrc : TVarData) : Single;
  435. begin
  436. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  437. DumpVariant('VariantToSingle', VargSrc);
  438. end; {$ENDIF}
  439. with VargSrc do
  440. case vType and not varTypeMask of
  441. 0: case vType of
  442. varEmpty : Result := 0;
  443. varSmallInt : Result := vSmallInt;
  444. varShortInt : Result := vShortInt;
  445. varInteger : Result := vInteger;
  446. varSingle : Result := vSingle;
  447. varDouble : Result := vDouble;
  448. varCurrency : Result := vCurrency;
  449. varDate : Result := vDate;
  450. varBoolean : Result := SmallInt(vBoolean);
  451. varVariant : Result := VariantToSingle(PVarData(vPointer)^);
  452. varByte : Result := vByte;
  453. varWord : Result := vWord;
  454. varLongWord : Result := vLongWord;
  455. varInt64 : Result := vInt64;
  456. varQword : Result := vQWord;
  457. varOleStr : Result := WStrToSingle(vOleStr);
  458. varString : Result := LStrToSingle(vString);
  459. varUString : Result := UStrToSingle(vString);
  460. else
  461. VariantTypeMismatch(vType, varSingle);
  462. end;
  463. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  464. varSmallInt : Result := PSmallInt(vPointer)^;
  465. varShortInt : Result := PShortInt(vPointer)^;
  466. varInteger : Result := PInteger(vPointer)^;
  467. varSingle : Result := PSingle(vPointer)^;
  468. varDouble : Result := PDouble(vPointer)^;
  469. varCurrency : Result := PCurrency(vPointer)^;
  470. varDate : Result := PDate(vPointer)^;
  471. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  472. varVariant : Result := VariantToSingle(PVarData(vPointer)^);
  473. varByte : Result := PByte(vPointer)^;
  474. varWord : Result := PWord(vPointer)^;
  475. varLongWord : Result := PLongWord(vPointer)^;
  476. varInt64 : Result := PInt64(vPointer)^;
  477. varQword : Result := PQWord(vPointer)^;
  478. varOleStr : Result := WStrToSingle(PPointer(vPointer)^);
  479. varString : Result := LStrToSingle(PPointer(vPointer)^);
  480. varUString : Result := UStrToSingle(PPointer(vPointer)^);
  481. else { other vtype }
  482. VariantTypeMismatch(vType, varSingle);
  483. end else { pointer is nil }
  484. VariantTypeMismatch(vType, varSingle);
  485. else { array or something like that }
  486. VariantTypeMismatch(vType, varSingle);
  487. end;
  488. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  489. WriteLn('VariantToSingle -> ', Result);
  490. end; {$ENDIF}
  491. end;
  492. {--- Double ---}
  493. Function WStrToDouble(p: Pointer) : Double;
  494. var
  495. s : ShortString;
  496. Error : Word;
  497. begin
  498. if Length(WideString(p)) > 255 then
  499. VariantTypeMismatch(varOleStr, varDouble);
  500. s := WideString(p);
  501. PrepareFloatStr(s);
  502. Val(s, Result, Error);
  503. if Error <> 0 then
  504. VariantTypeMismatch(varOleStr, varDouble);
  505. end;
  506. Function LStrToDouble(p: Pointer) : Double;
  507. var
  508. s : ShortString;
  509. Error : Word;
  510. begin
  511. if Length(AnsiString(p)) > 255 then
  512. VariantTypeMismatch(varString, varDouble);
  513. s := AnsiString(p);
  514. PrepareFloatStr(s);
  515. Val(s, Result, Error);
  516. if Error <> 0 then
  517. VariantTypeMismatch(varString, varDouble);
  518. end;
  519. Function UStrToDouble(p: Pointer) : Double;
  520. var
  521. s : ShortString;
  522. Error : Word;
  523. begin
  524. if Length(UnicodeString(p)) > 255 then
  525. VariantTypeMismatch(varUString, varDouble);
  526. s := UnicodeString(p);
  527. PrepareFloatStr(s);
  528. Val(s, Result, Error);
  529. if Error <> 0 then
  530. VariantTypeMismatch(varUString, varDouble);
  531. end;
  532. Function VariantToDouble(const VargSrc : TVarData) : Double;
  533. begin
  534. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  535. DumpVariant('VariantToDouble', VargSrc);
  536. end; {$ENDIF}
  537. with VargSrc do
  538. case vType and not varTypeMask of
  539. 0: case vType of
  540. varEmpty : Result := 0;
  541. varSmallInt : Result := vSmallInt;
  542. varShortInt : Result := vShortInt;
  543. varInteger : Result := vInteger;
  544. varSingle : Result := vSingle;
  545. varDouble : Result := vDouble;
  546. varCurrency : Result := vCurrency;
  547. varDate : Result := vDate;
  548. varBoolean : Result := SmallInt(vBoolean);
  549. varVariant : Result := VariantToDouble(PVarData(vPointer)^);
  550. varByte : Result := vByte;
  551. varWord : Result := vWord;
  552. varLongWord : Result := vLongWord;
  553. varInt64 : Result := vInt64;
  554. varQword : Result := vQWord;
  555. varOleStr : Result := WStrToDouble(vOleStr);
  556. varString : Result := LStrToDouble(vString);
  557. varUString : Result := UStrToDouble(vString);
  558. else
  559. VariantTypeMismatch(vType, varDouble);
  560. end;
  561. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  562. varSmallInt : Result := PSmallInt(vPointer)^;
  563. varShortInt : Result := PShortInt(vPointer)^;
  564. varInteger : Result := PInteger(vPointer)^;
  565. varSingle : Result := PSingle(vPointer)^;
  566. varDouble : Result := PDouble(vPointer)^;
  567. varCurrency : Result := PCurrency(vPointer)^;
  568. varDate : Result := PDate(vPointer)^;
  569. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  570. varVariant : Result := VariantToDouble(PVarData(vPointer)^);
  571. varByte : Result := PByte(vPointer)^;
  572. varWord : Result := PWord(vPointer)^;
  573. varLongWord : Result := PLongWord(vPointer)^;
  574. varInt64 : Result := PInt64(vPointer)^;
  575. varQword : Result := PQWord(vPointer)^;
  576. varOleStr : Result := WStrToDouble(PPointer(vPointer)^);
  577. varString : Result := LStrToDouble(PPointer(vPointer)^);
  578. varUString : Result := UStrToDouble(PPointer(vPointer)^);
  579. else { other vtype }
  580. VariantTypeMismatch(vType, varDouble);
  581. end else { pointer is nil }
  582. VariantTypeMismatch(vType, varDouble);
  583. else { array or something like that }
  584. VariantTypeMismatch(vType, varDouble);
  585. end;
  586. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  587. WriteLn('VariantToDouble -> ', Result);
  588. end; {$ENDIF}
  589. end;
  590. {$endif FPUNONE}
  591. {--- Currency ---}
  592. Function WStrToCurrency(p: Pointer) : Currency;
  593. var
  594. s : ShortString;
  595. Error : Word;
  596. {$IFNDEF FPC_HAS_STR_CURRENCY}
  597. Temp : Extended;
  598. {$ENDIF FPC_HAS_STR_CURRENCY}
  599. begin
  600. if Length(WideString(p)) > 255 then
  601. VariantTypeMismatch(varOleStr, varCurrency);
  602. s := WideString(p);
  603. PrepareFloatStr(s);
  604. {$IFDEF FPC_HAS_STR_CURRENCY}
  605. Val(s, Result, Error);
  606. {$ELSE FPC_HAS_STR_CURRENCY} { needed for platforms where Currency = Int64 }
  607. Val(s, Temp, Error);
  608. Result := Temp;
  609. {$ENDIF FPC_HAS_STR_CURRENCY}
  610. if Error <> 0 then
  611. VariantTypeMismatch(varOleStr, varCurrency);
  612. end;
  613. Function LStrToCurrency(p: Pointer) : Currency;
  614. var
  615. s : ShortString;
  616. Error : Word;
  617. {$IFNDEF FPC_HAS_STR_CURRENCY}
  618. Temp : Extended;
  619. {$ENDIF FPC_HAS_STR_CURRENCY}
  620. begin
  621. if Length(AnsiString(p)) > 255 then
  622. VariantTypeMismatch(varString, varCurrency);
  623. s := AnsiString(p);
  624. PrepareFloatStr(s);
  625. {$IFDEF FPC_HAS_STR_CURRENCY}
  626. Val(s, Result, Error);
  627. {$ELSE FPC_HAS_STR_CURRENCY} { needed for platforms where Currency = Int64 }
  628. Val(s, Temp, Error);
  629. Result := Temp;
  630. {$ENDIF FPC_HAS_STR_CURRENCY}
  631. if Error <> 0 then
  632. VariantTypeMismatch(varString, varCurrency);
  633. end;
  634. Function UStrToCurrency(p: Pointer) : Currency;
  635. var
  636. s : ShortString;
  637. Error : Word;
  638. {$IFNDEF FPC_HAS_STR_CURRENCY}
  639. Temp : Extended;
  640. {$ENDIF FPC_HAS_STR_CURRENCY}
  641. begin
  642. if Length(UnicodeString(p)) > 255 then
  643. VariantTypeMismatch(varUString, varCurrency);
  644. s := UnicodeString(p);
  645. PrepareFloatStr(s);
  646. {$IFDEF FPC_HAS_STR_CURRENCY}
  647. Val(s, Result, Error);
  648. {$ELSE FPC_HAS_STR_CURRENCY} { needed for platforms where Currency = Int64 }
  649. Val(s, Temp, Error);
  650. Result := Temp;
  651. {$ENDIF FPC_HAS_STR_CURRENCY}
  652. if Error <> 0 then
  653. VariantTypeMismatch(varUString, varCurrency);
  654. end;
  655. Function VariantToCurrency(const VargSrc : TVarData) : Currency;
  656. begin
  657. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  658. DumpVariant('VariantToCurrency', VargSrc);
  659. end; {$ENDIF}
  660. with VargSrc do
  661. case vType and not varTypeMask of
  662. 0: case vType of
  663. varEmpty : Result := 0;
  664. varSmallInt : Result := vSmallInt;
  665. varShortInt : Result := vShortInt;
  666. varInteger : Result := vInteger;
  667. {$ifndef FPUNONE}
  668. varSingle : begin
  669. if (vSingle > MaxCurrency) or (vSingle < MinCurrency) then
  670. VariantTypeMismatch(vType, varCurrency);
  671. Result := vSingle;
  672. end;
  673. varDouble : begin
  674. if (vDouble > MaxCurrency) or (vDouble < MinCurrency) then
  675. VariantTypeMismatch(vType, varCurrency);
  676. Result := vDouble;
  677. end;
  678. varDate : begin
  679. if (vDate > MaxCurrency) or (vDate < MinCurrency) then
  680. VariantTypeMismatch(vType, varCurrency);
  681. Result := vDate;
  682. end;
  683. {$endif}
  684. varCurrency : Result := vCurrency;
  685. varBoolean : Result := SmallInt(vBoolean);
  686. varVariant : Result := VariantToCurrency(PVarData(vPointer)^);
  687. varByte : Result := vByte;
  688. varWord : Result := vWord;
  689. varLongWord : Result := vLongWord;
  690. varInt64 : Result := vInt64;
  691. varQword : Result := currency(vQWord);
  692. varOleStr : Result := WStrToCurrency(vOleStr);
  693. varString : Result := LStrToCurrency(vString);
  694. varUString : Result := UStrToCurrency(vString);
  695. else
  696. VariantTypeMismatch(vType, varCurrency);
  697. end;
  698. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  699. varSmallInt : Result := PSmallInt(vPointer)^;
  700. varShortInt : Result := PShortInt(vPointer)^;
  701. varInteger : Result := PInteger(vPointer)^;
  702. {$ifndef FPUNONE}
  703. varSingle : begin
  704. if (PSingle(vPointer)^ > MaxCurrency) or (PSingle(vPointer)^ < MinCurrency) then
  705. VariantTypeMismatch(vType, varCurrency);
  706. Result := PSingle(vPointer)^;
  707. end;
  708. varDouble : begin
  709. if (PDouble(vPointer)^ > MaxCurrency) or (PDouble(vPointer)^ < MinCurrency) then
  710. VariantTypeMismatch(vType, varCurrency);
  711. Result := PDouble(vPointer)^;
  712. end;
  713. varDate : begin
  714. if (PDate(vPointer)^ > MaxCurrency) or (PDate(vPointer)^ < MinCurrency) then
  715. VariantTypeMismatch(vType, varCurrency);
  716. Result := PDate(vPointer)^;
  717. end;
  718. {$endif}
  719. varCurrency : Result := PCurrency(vPointer)^;
  720. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  721. varVariant : Result := VariantToCurrency(PVarData(vPointer)^);
  722. varByte : Result := PByte(vPointer)^;
  723. varWord : Result := PWord(vPointer)^;
  724. varLongWord : Result := PLongWord(vPointer)^;
  725. varInt64 : Result := PInt64(vPointer)^;
  726. varQword : Result := currency(PQWord(vPointer)^);
  727. varOleStr : Result := WStrToCurrency(PPointer(vPointer)^);
  728. varString : Result := LStrToCurrency(PPointer(vPointer)^);
  729. varUString : Result := UStrToCurrency(PPointer(vPointer)^);
  730. else { other vtype }
  731. VariantTypeMismatch(vType, varCurrency);
  732. end else { pointer is nil }
  733. VariantTypeMismatch(vType, varCurrency);
  734. else { array or something like that }
  735. VariantTypeMismatch(vType, varCurrency);
  736. end;
  737. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  738. WriteLn('VariantToCurrency -> ', Result);
  739. end; {$ENDIF}
  740. end;
  741. {--- Date ---}
  742. {$ifndef FPUNONE}
  743. Function WStrToDate(p: Pointer) : TDateTime;
  744. var
  745. s: string;
  746. begin
  747. s := WideString(p);
  748. if not (TryStrToDateTime(s, Result) or
  749. TryStrToDate(s, Result) or
  750. TryStrToTime(s, Result)) then
  751. VariantTypeMismatch(varOleStr, varDate);
  752. end;
  753. Function LStrToDate(p: Pointer) : TDateTime;
  754. begin
  755. if not (TryStrToDateTime(AnsiString(p), Result) or
  756. TryStrToDate(AnsiString(p), Result) or
  757. TryStrToTime(AnsiString(p), Result)) then
  758. VariantTypeMismatch(varString, varDate);
  759. end;
  760. Function UStrToDate(p: Pointer) : TDateTime;
  761. begin
  762. if not (TryStrToDateTime(UnicodeString(p), Result) or
  763. TryStrToDate(UnicodeString(p), Result) or
  764. TryStrToTime(UnicodeString(p), Result)) then
  765. VariantTypeMismatch(varUString, varDate);
  766. end;
  767. Function VariantToDate(const VargSrc : TVarData) : TDateTime;
  768. begin
  769. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  770. DumpVariant('VariantToDate', VargSrc);
  771. end; {$ENDIF}
  772. with VargSrc do
  773. case vType and not varTypeMask of
  774. 0: case vType of
  775. varEmpty : Result := 0;
  776. varSmallInt : Result := vSmallInt;
  777. varShortInt : Result := vShortInt;
  778. varInteger : Result := vInteger;
  779. varSingle : Result := vSingle;
  780. varDouble : Result := vDouble;
  781. varCurrency : Result := vCurrency;
  782. varDate : Result := vDate;
  783. varBoolean : Result := SmallInt(vBoolean);
  784. varVariant : Result := VariantToDate(PVarData(vPointer)^);
  785. varByte : Result := vByte;
  786. varWord : Result := vWord;
  787. varLongWord : Result := vLongWord;
  788. varInt64 : Result := vInt64;
  789. varQword : Result := vQWord;
  790. varOleStr : Result := WStrToDate(vOleStr);
  791. varString : Result := LStrToDate(vString);
  792. varUString : Result := UStrToDate(vString);
  793. else
  794. VariantTypeMismatch(vType, varDate);
  795. end;
  796. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  797. varSmallInt : Result := PSmallInt(vPointer)^;
  798. varShortInt : Result := PShortInt(vPointer)^;
  799. varInteger : Result := PInteger(vPointer)^;
  800. varSingle : Result := PSingle(vPointer)^;
  801. varDouble : Result := PDouble(vPointer)^;
  802. varCurrency : Result := PCurrency(vPointer)^;
  803. varDate : Result := PDate(vPointer)^;
  804. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  805. varVariant : Result := VariantToDate(PVarData(vPointer)^);
  806. varByte : Result := PByte(vPointer)^;
  807. varWord : Result := PWord(vPointer)^;
  808. varLongWord : Result := PLongWord(vPointer)^;
  809. varInt64 : Result := PInt64(vPointer)^;
  810. varQword : Result := PQWord(vPointer)^;
  811. varOleStr : Result := WStrToDate(PPointer(vPointer)^);
  812. varString : Result := LStrToDate(PPointer(vPointer)^);
  813. varUString : Result := UStrToDate(PPointer(vPointer)^);
  814. else { other vtype }
  815. VariantTypeMismatch(vType, varDate);
  816. end else { pointer is nil }
  817. VariantTypeMismatch(vType, varDate);
  818. else { array or something like that }
  819. VariantTypeMismatch(vType, varDate);
  820. end;
  821. if (Result < MinDateTime) or (Result > MaxDateTime) then
  822. VariantTypeMismatch(VargSrc.vType, varDate);
  823. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  824. WriteLn('VariantToDate -> ', Result);
  825. end; {$ENDIF}
  826. end;
  827. {$endif}
  828. {--- Boolean ---}
  829. Function WStrToBoolean(p: Pointer) : Boolean;
  830. begin
  831. if not TryStrToBool(WideString(p), Result) then
  832. VariantTypeMismatch(varOleStr, varBoolean);
  833. end;
  834. Function LStrToBoolean(p: Pointer) : Boolean;
  835. begin
  836. if not TryStrToBool(AnsiString(p), Result) then
  837. VariantTypeMismatch(varString, varBoolean);
  838. end;
  839. Function UStrToBoolean(p: Pointer) : Boolean;
  840. begin
  841. if not TryStrToBool(UnicodeString(p), Result) then
  842. VariantTypeMismatch(varUString, varBoolean);
  843. end;
  844. Function VariantToBoolean(const VargSrc : TVarData) : Boolean;
  845. begin
  846. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  847. DumpVariant('VariantToBoolean', VargSrc);
  848. end; {$ENDIF}
  849. with VargSrc do
  850. case vType and not varTypeMask of
  851. 0: case vType of
  852. varEmpty : Result := False;
  853. varSmallInt : Result := vSmallInt <> 0;
  854. varShortInt : Result := vShortInt <> 0;
  855. varInteger : Result := vInteger <> 0;
  856. {$ifndef FPUNONE}
  857. varSingle : Result := vSingle <> 0;
  858. varDouble : Result := vDouble <> 0;
  859. varCurrency : Result := vCurrency <> 0;
  860. varDate : Result := vDate <> 0;
  861. {$endif}
  862. varBoolean : Result := vBoolean;
  863. varVariant : Result := VariantToBoolean(PVarData(vPointer)^);
  864. varByte : Result := vByte <> 0;
  865. varWord : Result := vWord <> 0;
  866. varLongWord : Result := vLongWord <> 0;
  867. varInt64 : Result := vInt64 <> 0;
  868. varQword : Result := vQWord <> 0;
  869. varOleStr : Result := WStrToBoolean(vOleStr);
  870. varString : Result := LStrToBoolean(vString);
  871. varUString : Result := UStrToBoolean(vString);
  872. else
  873. VariantTypeMismatch(vType, varBoolean);
  874. end;
  875. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  876. varSmallInt : Result := PSmallInt(vPointer)^ <> 0;
  877. varShortInt : Result := PShortInt(vPointer)^ <> 0;
  878. varInteger : Result := PInteger(vPointer)^ <> 0;
  879. {$ifndef FPUNONE}
  880. varSingle : Result := PSingle(vPointer)^ <> 0;
  881. varDouble : Result := PDouble(vPointer)^ <> 0;
  882. varCurrency : Result := PCurrency(vPointer)^ <> 0;
  883. varDate : Result := PDate(vPointer)^ <> 0;
  884. {$endif}
  885. varBoolean : Result := SmallInt(PWordBool(vPointer)^) <> 0;
  886. varVariant : Result := VariantToBoolean(PVarData(vPointer)^);
  887. varByte : Result := PByte(vPointer)^ <> 0;
  888. varWord : Result := PWord(vPointer)^ <> 0;
  889. varLongWord : Result := PLongWord(vPointer)^ <> 0;
  890. varInt64 : Result := PInt64(vPointer)^ <> 0;
  891. varQword : Result := PQWord(vPointer)^ <> 0;
  892. varOleStr : Result := WStrToBoolean(PPointer(vPointer)^);
  893. varString : Result := LStrToBoolean(PPointer(vPointer)^);
  894. varUString : Result := UStrToBoolean(PPointer(vPointer)^);
  895. else { other vtype }
  896. VariantTypeMismatch(vType, varBoolean);
  897. end else { pointer is nil }
  898. Result := False;
  899. else { array or something like that }
  900. VariantTypeMismatch(vType, varBoolean);
  901. end;
  902. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  903. WriteLn('VariantToBoolean -> ', Result);
  904. end; {$ENDIF}
  905. end;
  906. {--- Byte ---}
  907. Function WStrToByte(p: Pointer) : Byte;
  908. var
  909. Error : Word;
  910. begin
  911. Val(WideString(p), Result, Error);
  912. if Error <> 0 then
  913. VariantTypeMismatch(varOleStr, varByte);
  914. end;
  915. Function LStrToByte(p: Pointer) : Byte;
  916. var
  917. Error : Word;
  918. begin
  919. Val(AnsiString(p), Result, Error);
  920. if Error <> 0 then
  921. VariantTypeMismatch(varString, varByte);
  922. end;
  923. Function UStrToByte(p: Pointer) : Byte;
  924. var
  925. Error : Word;
  926. begin
  927. Val(UnicodeString(p), Result, Error);
  928. if Error <> 0 then
  929. VariantTypeMismatch(varUString, varByte);
  930. end;
  931. Function VariantToByte(const VargSrc : TVarData) : Byte;
  932. begin
  933. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  934. DumpVariant('VariantToByte', VargSrc);
  935. end; {$ENDIF}
  936. with VargSrc do
  937. case vType and not varTypeMask of
  938. 0: case vType of
  939. varEmpty : Result := 0;
  940. varSmallInt : Result := byte(vSmallInt);
  941. varShortInt : Result := byte(vShortInt);
  942. varInteger : Result := byte(vInteger);
  943. {$ifndef FPUNONE}
  944. varSingle : Result := byte(Round(vSingle));
  945. varDouble : Result := byte(Round(vDouble));
  946. varCurrency : Result := byte(Round(vCurrency));
  947. varDate : Result := byte(Round(vDate));
  948. {$endif}
  949. varBoolean : Result := byte(SmallInt(vBoolean));
  950. varVariant : Result := VariantToByte(PVarData(vPointer)^);
  951. varByte : Result := vByte;
  952. varWord : Result := byte(vWord);
  953. varLongWord : Result := byte(vLongWord);
  954. varInt64 : Result := byte(vInt64);
  955. varQword : Result := byte(vQWord);
  956. varOleStr : Result := WStrToByte(vOleStr);
  957. varString : Result := LStrToByte(vString);
  958. varUString : Result := UStrToByte(vString);
  959. else
  960. VariantTypeMismatch(vType, varByte);
  961. end;
  962. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  963. varSmallInt : Result := byte(PSmallInt(vPointer)^);
  964. varShortInt : Result := byte(PShortInt(vPointer)^);
  965. varInteger : Result := byte(PInteger(vPointer)^);
  966. {$ifndef FPUNONE}
  967. varSingle : Result := byte(Round(PSingle(vPointer)^));
  968. varDouble : Result := byte(Round(PDouble(vPointer)^));
  969. varCurrency : Result := byte(Round(PCurrency(vPointer)^));
  970. varDate : Result := byte(Round(PDate(vPointer)^));
  971. {$endif}
  972. varBoolean : Result := byte(SmallInt(PWordBool(vPointer)^));
  973. varVariant : Result := byte(VariantToByte(PVarData(vPointer)^));
  974. varByte : Result := PByte(vPointer)^;
  975. varWord : Result := byte(PWord(vPointer)^);
  976. varLongWord : Result := byte(PLongWord(vPointer)^);
  977. varInt64 : Result := byte(PInt64(vPointer)^);
  978. varQword : Result := byte(PQWord(vPointer)^);
  979. varOleStr : Result := WStrToByte(PPointer(vPointer)^);
  980. varString : Result := LStrToByte(PPointer(vPointer)^);
  981. varUString : Result := UStrToByte(PPointer(vPointer)^);
  982. else { other vtype }
  983. VariantTypeMismatch(vType, varByte);
  984. end else { pointer is nil }
  985. VariantTypeMismatch(vType, varByte);
  986. else { array or something like that }
  987. VariantTypeMismatch(vType, varByte);
  988. end;
  989. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  990. WriteLn('VariantToByte -> ', Result);
  991. end; {$ENDIF}
  992. end;
  993. {--- Int64 ---}
  994. Function WStrToInt64(p: Pointer) : Int64;
  995. var
  996. Error : Word;
  997. begin
  998. Val(WideString(p), Result, Error);
  999. if Error <> 0 then
  1000. VariantTypeMismatch(varOleStr, varInt64);
  1001. end;
  1002. Function LStrToInt64(p: Pointer) : Int64;
  1003. var
  1004. Error : Word;
  1005. begin
  1006. Val(AnsiString(p), Result, Error);
  1007. if Error <> 0 then
  1008. VariantTypeMismatch(varString, varInt64);
  1009. end;
  1010. Function UStrToInt64(p: Pointer) : Int64;
  1011. var
  1012. Error : Word;
  1013. begin
  1014. Val(UnicodeString(p), Result, Error);
  1015. if Error <> 0 then
  1016. VariantTypeMismatch(varUString, varInt64);
  1017. end;
  1018. Function VariantToInt64(const VargSrc : TVarData) : Int64;
  1019. begin
  1020. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1021. DumpVariant('VariantToInt64', VargSrc);
  1022. end; {$ENDIF}
  1023. with VargSrc do
  1024. case vType and not varTypeMask of
  1025. 0: case vType of
  1026. varEmpty : Result := 0;
  1027. varSmallInt : Result := vSmallInt;
  1028. varShortInt : Result := vShortInt;
  1029. varInteger : Result := vInteger;
  1030. {$ifndef FPUNONE}
  1031. varSingle : Result := Round(vSingle);
  1032. varDouble : Result := Round(vDouble);
  1033. varCurrency : Result := Round(vCurrency);
  1034. varDate : Result := Round(vDate);
  1035. {$endif}
  1036. varBoolean : Result := SmallInt(vBoolean);
  1037. varVariant : Result := VariantToInt64(PVarData(vPointer)^);
  1038. varByte : Result := vByte;
  1039. varWord : Result := vWord;
  1040. varLongWord : Result := vLongWord;
  1041. varInt64 : Result := vInt64;
  1042. varQword : Result := int64(vQWord);
  1043. varOleStr : Result := WStrToInt64(vOleStr);
  1044. varString : Result := LStrToInt64(vString);
  1045. varUString : Result := UStrToInt64(vString);
  1046. else
  1047. VariantTypeMismatch(vType, varInt64);
  1048. end;
  1049. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  1050. varSmallInt : Result := PSmallInt(vPointer)^;
  1051. varShortInt : Result := PShortInt(vPointer)^;
  1052. varInteger : Result := PInteger(vPointer)^;
  1053. {$ifndef FPUNONE}
  1054. varSingle : Result := Round(PSingle(vPointer)^);
  1055. varDouble : Result := Round(PDouble(vPointer)^);
  1056. varCurrency : Result := Round(PCurrency(vPointer)^);
  1057. varDate : Result := Round(PDate(vPointer)^);
  1058. {$endif}
  1059. varBoolean : Result := SmallInt(PWordBool(vPointer)^);
  1060. varVariant : Result := VariantToInt64(PVarData(vPointer)^);
  1061. varByte : Result := PByte(vPointer)^;
  1062. varWord : Result := PWord(vPointer)^;
  1063. varLongWord : Result := PLongWord(vPointer)^;
  1064. varInt64 : Result := PInt64(vPointer)^;
  1065. varQword : Result := PQWord(vPointer)^;
  1066. varOleStr : Result := WStrToInt64(PPointer(vPointer)^);
  1067. varString : Result := LStrToInt64(PPointer(vPointer)^);
  1068. varUString : Result := UStrToInt64(PPointer(vPointer)^);
  1069. else { other vtype }
  1070. VariantTypeMismatch(vType, varInt64);
  1071. end else { pointer is nil }
  1072. VariantTypeMismatch(vType, varInt64);
  1073. else { array or something like that }
  1074. VariantTypeMismatch(vType, varInt64);
  1075. end;
  1076. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1077. WriteLn('VariantToInt64 -> ', Result);
  1078. end; {$ENDIF}
  1079. end;
  1080. {--- QWord ---}
  1081. Function WStrToQWord(p: Pointer) : QWord;
  1082. var
  1083. Error : Word;
  1084. begin
  1085. Val(WideString(p), Result, Error);
  1086. if Error <> 0 then
  1087. VariantTypeMismatch(varOleStr, varQWord);
  1088. end;
  1089. Function LStrToQWord(p: Pointer) : QWord;
  1090. var
  1091. Error : Word;
  1092. begin
  1093. Val(AnsiString(p), Result, Error);
  1094. if Error <> 0 then
  1095. VariantTypeMismatch(varString, varQWord);
  1096. end;
  1097. Function UStrToQWord(p: Pointer) : QWord;
  1098. var
  1099. Error : Word;
  1100. begin
  1101. Val(UnicodeString(p), Result, Error);
  1102. if Error <> 0 then
  1103. VariantTypeMismatch(varUString, varQWord);
  1104. end;
  1105. Function VariantToQWord(const VargSrc : TVarData) : QWord;
  1106. begin
  1107. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1108. DumpVariant('VariantToQWord', VargSrc);
  1109. end; {$ENDIF}
  1110. with VargSrc do
  1111. case vType and not varTypeMask of
  1112. 0: case vType of
  1113. varEmpty : Result := 0;
  1114. varSmallInt : Result := qword(vSmallInt);
  1115. varShortInt : Result := qword(vShortInt);
  1116. varInteger : Result := qword(vInteger);
  1117. {$ifndef FPUNONE}
  1118. varSingle : Result := qword(Round(vSingle));
  1119. varDouble : Result := qword(Round(vDouble));
  1120. varCurrency : Result := qword(Round(vCurrency));
  1121. varDate : Result := qword(Round(vDate));
  1122. {$endif}
  1123. varBoolean : Result := qword(SmallInt(vBoolean));
  1124. varVariant : Result := VariantToQWord(PVarData(vPointer)^);
  1125. varByte : Result := vByte;
  1126. varWord : Result := vWord;
  1127. varLongWord : Result := vLongWord;
  1128. varInt64 : Result := qword(vInt64);
  1129. varQword : Result := vQWord;
  1130. varOleStr : Result := WStrToQWord(vOleStr);
  1131. varString : Result := LStrToQWord(vString);
  1132. varUString : Result := UStrToQWord(vString);
  1133. else
  1134. VariantTypeMismatch(vType, varQWord);
  1135. end;
  1136. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  1137. varSmallInt : Result := qword(PSmallInt(vPointer)^);
  1138. varShortInt : Result := qword(PShortInt(vPointer)^);
  1139. varInteger : Result := qword(PInteger(vPointer)^);
  1140. {$ifndef FPUNONE}
  1141. varSingle : Result := qword(Round(PSingle(vPointer)^));
  1142. varDouble : Result := qword(Round(PDouble(vPointer)^));
  1143. varCurrency : Result := qword(Round(PCurrency(vPointer)^));
  1144. varDate : Result := qword(Round(PDate(vPointer)^));
  1145. {$endif}
  1146. varBoolean : Result := qword(SmallInt(PWordBool(vPointer)^));
  1147. varVariant : Result := VariantToQWord(PVarData(vPointer)^);
  1148. varByte : Result := PByte(vPointer)^;
  1149. varWord : Result := PWord(vPointer)^;
  1150. varLongWord : Result := PLongWord(vPointer)^;
  1151. varInt64 : Result := qword(PInt64(vPointer)^);
  1152. varQword : Result := PQWord(vPointer)^;
  1153. varOleStr : Result := WStrToQWord(PPointer(vPointer)^);
  1154. varString : Result := LStrToQWord(PPointer(vPointer)^);
  1155. varUString : Result := UStrToQWord(PPointer(vPointer)^);
  1156. else { other vtype }
  1157. VariantTypeMismatch(vType, varQWord);
  1158. end else { pointer is nil }
  1159. VariantTypeMismatch(vType, varQWord);
  1160. else { array or something like that }
  1161. VariantTypeMismatch(vType, varQWord);
  1162. end;
  1163. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1164. WriteLn('VariantToQWord -> ', Result);
  1165. end; {$ENDIF}
  1166. end;
  1167. function VarDateToString(DT: TDateTime): AnsiString;
  1168. begin
  1169. if Trunc(DT) = 0 then
  1170. Result := TimeToStr(DT)
  1171. else
  1172. Result := DateTimeToStr(DT);
  1173. end;
  1174. {--- WideString ---}
  1175. Function VariantToWideString(const VargSrc : TVarData) : WideString;
  1176. begin
  1177. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1178. DumpVariant('VariantToWideString', VargSrc);
  1179. end; {$ENDIF}
  1180. with VargSrc do
  1181. case vType and not varTypeMask of
  1182. 0: case vType of
  1183. varEmpty : Result := '';
  1184. varSmallInt : Result := IntToStr(vSmallInt);
  1185. varShortInt : Result := IntToStr(vShortInt);
  1186. varInteger : Result := IntToStr(vInteger);
  1187. {$ifndef FPUNONE}
  1188. varSingle : Result := FloatToStr(vSingle);
  1189. varDouble : Result := FloatToStr(vDouble);
  1190. varCurrency : Result := FloatToStr(vCurrency);
  1191. varDate : Result := VarDateToString(vDate);
  1192. {$endif}
  1193. varBoolean : Result := BoolToStr(vBoolean, True);
  1194. varVariant : Result := VariantToWideString(PVarData(vPointer)^);
  1195. varByte : Result := IntToStr(vByte);
  1196. varWord : Result := IntToStr(vWord);
  1197. varLongWord : Result := IntToStr(vLongWord);
  1198. varInt64 : Result := IntToStr(vInt64);
  1199. varQword : Result := IntToStr(vQWord);
  1200. varOleStr : Result := WideString(Pointer(vOleStr));
  1201. varString : Result := AnsiString(vString);
  1202. varUString : Result := UnicodeString(vString);
  1203. else
  1204. VariantTypeMismatch(vType, varOleStr);
  1205. end;
  1206. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  1207. varSmallInt : Result := IntToStr(PSmallInt(vPointer)^);
  1208. varShortInt : Result := IntToStr(PShortInt(vPointer)^);
  1209. varInteger : Result := IntToStr(PInteger(vPointer)^);
  1210. {$ifndef FPUNONE}
  1211. varSingle : Result := FloatToStr(PSingle(vPointer)^);
  1212. varDouble : Result := FloatToStr(PDouble(vPointer)^);
  1213. varCurrency : Result := FloatToStr(PCurrency(vPointer)^);
  1214. varDate : Result := VarDateToString(PDate(vPointer)^);
  1215. {$endif}
  1216. varBoolean : Result := BoolToStr(PWordBool(vPointer)^, True);
  1217. varVariant : Result := VariantToWideString(PVarData(vPointer)^);
  1218. varByte : Result := IntToStr(PByte(vPointer)^);
  1219. varWord : Result := IntToStr(PWord(vPointer)^);
  1220. varLongWord : Result := IntToStr(PLongWord(vPointer)^);
  1221. varInt64 : Result := IntToStr(PInt64(vPointer)^);
  1222. varQword : Result := IntToStr(PQWord(vPointer)^);
  1223. varOleStr : Result := WideString(PPointer(vPointer)^);
  1224. varString : Result := AnsiString(PPointer(vPointer)^);
  1225. varUString : Result := UnicodeString(PPointer(vPointer)^);
  1226. else { other vtype }
  1227. VariantTypeMismatch(vType, varOleStr);
  1228. end else { pointer is nil }
  1229. VariantTypeMismatch(vType, varOleStr);
  1230. else { array or something like that }
  1231. VariantTypeMismatch(vType, varOleStr);
  1232. end;
  1233. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1234. WriteLn('VariantToWideString -> ', Result);
  1235. end; {$ENDIF}
  1236. end;
  1237. {--- AnsiString ---}
  1238. Function VariantToAnsiString(const VargSrc : TVarData) : AnsiString;
  1239. begin
  1240. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1241. DumpVariant('VariantToAnsiString', VargSrc);
  1242. end; {$ENDIF}
  1243. with VargSrc do
  1244. case vType and not varTypeMask of
  1245. 0: case vType of
  1246. varEmpty : Result := '';
  1247. varSmallInt : Result := IntToStr(vSmallInt);
  1248. varShortInt : Result := IntToStr(vShortInt);
  1249. varInteger : Result := IntToStr(vInteger);
  1250. {$ifndef FPUNONE}
  1251. varSingle : Result := FloatToStr(vSingle);
  1252. varDouble : Result := FloatToStr(vDouble);
  1253. varCurrency : Result := FloatToStr(vCurrency);
  1254. varDate : Result := VarDateToString(vDate);
  1255. {$endif}
  1256. varBoolean : Result := BoolToStr(vBoolean, True);
  1257. varVariant : Result := VariantToAnsiString(PVarData(vPointer)^);
  1258. varByte : Result := IntToStr(vByte);
  1259. varWord : Result := IntToStr(vWord);
  1260. varLongWord : Result := IntToStr(vLongWord);
  1261. varInt64 : Result := IntToStr(vInt64);
  1262. varQword : Result := IntToStr(vQWord);
  1263. varOleStr : Result := WideString(Pointer(vOleStr));
  1264. varString : Result := AnsiString(vString);
  1265. varUString : Result := UnicodeString(vString);
  1266. else
  1267. VariantTypeMismatch(vType, varString);
  1268. end;
  1269. varByRef: if Assigned(vPointer) then case vType and varTypeMask of
  1270. varSmallInt : Result := IntToStr(PSmallInt(vPointer)^);
  1271. varShortInt : Result := IntToStr(PShortInt(vPointer)^);
  1272. varInteger : Result := IntToStr(PInteger(vPointer)^);
  1273. {$ifndef FPUNONE}
  1274. varSingle : Result := FloatToStr(PSingle(vPointer)^);
  1275. varDouble : Result := FloatToStr(PDouble(vPointer)^);
  1276. varCurrency : Result := FloatToStr(PCurrency(vPointer)^);
  1277. varDate : Result := VarDateToString(PDate(vPointer)^);
  1278. {$endif}
  1279. varBoolean : Result := BoolToStr(PWordBool(vPointer)^, True);
  1280. varVariant : Result := VariantToAnsiString(PVarData(vPointer)^);
  1281. varByte : Result := IntToStr(PByte(vPointer)^);
  1282. varWord : Result := IntToStr(PWord(vPointer)^);
  1283. varLongWord : Result := IntToStr(PLongWord(vPointer)^);
  1284. varInt64 : Result := IntToStr(PInt64(vPointer)^);
  1285. varQword : Result := IntToStr(PQWord(vPointer)^);
  1286. varOleStr : Result := WideString(PPointer(vPointer)^);
  1287. varString : Result := AnsiString(PPointer(vPointer)^);
  1288. varUString : Result := UnicodeString(PPointer(vPointer)^);
  1289. else { other vtype }
  1290. VariantTypeMismatch(vType, varString);
  1291. end else { pointer is nil }
  1292. VariantTypeMismatch(vType, varString);
  1293. else { array or something like that }
  1294. VariantTypeMismatch(vType, varString);
  1295. end;
  1296. {$IFDEF DEBUG_VARUTILS} if __DEBUG_VARUTILS then begin
  1297. WriteLn('VariantToAnsiString -> ', Result);
  1298. end; {$ENDIF}
  1299. end;
  1300. Function VariantToShortString(const VargSrc : TVarData) : ShortString;
  1301. begin
  1302. Result:=VariantToAnsiString(VargSrc);
  1303. end;
  1304. { ---------------------------------------------------------------------
  1305. Some debug routines
  1306. ---------------------------------------------------------------------}
  1307. Procedure DumpVariant(const VSrc : Variant);
  1308. begin
  1309. DumpVariant(Output, '', TVarData(VSrc));
  1310. end;
  1311. Procedure DumpVariant(const aName: string; const VSrc : Variant);
  1312. begin
  1313. DumpVariant(Output, aName, TVarData(VSrc));
  1314. end;
  1315. Procedure DumpVariant(Var F : Text; const VSrc : Variant);
  1316. begin
  1317. DumpVariant(F, '', TVarData(VSrc));
  1318. end;
  1319. procedure DumpVariant(var F : Text; const aName: string; const VSrc : Variant);
  1320. begin
  1321. DumpVariant(F, aName, TVarData(VSrc));
  1322. end;
  1323. Procedure DumpVariant(const VargSrc : TVarData);
  1324. begin
  1325. DumpVariant(Output, '', VargSrc);
  1326. end;
  1327. Procedure DumpVariant(const aName: string; const VargSrc : TVarData);
  1328. begin
  1329. DumpVariant(Output, aName, VargSrc);
  1330. end;
  1331. Procedure DumpVariant(Var F : Text; const VargSrc : TVarData);
  1332. begin
  1333. DumpVariant(F, '', VargSrc);
  1334. end;
  1335. const
  1336. VarTypeStrings : array [varEmpty..varQword] of string = (
  1337. 'empty', { varempty = 0 }
  1338. 'null', { varnull = 1 }
  1339. 'smallint', { varsmallint = 2 }
  1340. 'integer', { varinteger = 3 }
  1341. 'single', { varsingle = 4 }
  1342. 'double', { vardouble = 5 }
  1343. 'currency', { varcurrency = 6 }
  1344. 'date', { vardate = 7 }
  1345. 'olestr', { varolestr = 8 }
  1346. 'dispatch', { vardispatch = 9 }
  1347. 'error', { varerror = 10 }
  1348. 'boolean', { varboolean = 11 }
  1349. 'variant', { varvariant = 12 }
  1350. 'unknown', { varunknown = 13 }
  1351. 'decimal', { vardecimal = 14 }
  1352. 'undefined',
  1353. 'shortint', { varshortint = 16 }
  1354. 'byte', { varbyte = 17 }
  1355. 'word', { varword = 18 }
  1356. 'longword', { varlongword = 19 }
  1357. 'int64', { varint64 = 20 }
  1358. 'qword'); { varqword = 21 }
  1359. Procedure DumpVariant(Var F : Text; const aName: string; const VargSrc : TVarData);
  1360. Var
  1361. i: Integer;
  1362. begin
  1363. Writeln(F,'---> ', aName, ' at $', HexStr(@VargSrc), ' <----------------');
  1364. with VargSrc do begin
  1365. if vType and varByRef = varByRef then
  1366. Writeln(F,'Variant is by reference.');
  1367. if vType and varArray = varArray then
  1368. Writeln(F,'Variant is an array.');
  1369. if vType and not (varTypeMask or varArray or varByRef) <> 0 then
  1370. Writeln(F,'Variant has unknown flags set in type: $', IntToHex(vType, 4));
  1371. If (vType and varTypeMask) in [varEmpty..varQword] then
  1372. Writeln(F,'Variant has type : ', VarTypeStrings[vType and varTypeMask])
  1373. else If (vType and varTypeMask) = varString then
  1374. Writeln(F,'Variant has type : string')
  1375. else if (vType and varTypeMask) = varUString then
  1376. Writeln(F,'Variant has type : UnicodeString')
  1377. else
  1378. Writeln(F,'Variant has unknown type : $', IntToHex(vType and varTypeMask, 4));
  1379. Write('Bytes :');
  1380. for i := 0 to 13 do
  1381. Write(IntToHex(VBytes[i], 2),' ');
  1382. WriteLn;
  1383. if vType and varArray = varArray then begin
  1384. Writeln(F,'---< ', aName, ' at $', HexStr(@VargSrc), ' >----------------');
  1385. Writeln(F);
  1386. Exit;
  1387. end;
  1388. If vType <> varEmpty then begin
  1389. Write(F,'Value is: [');
  1390. if (vType and varByRef = varByRef) or (vType and varTypeMask = varVariant) then
  1391. if not Assigned(vPointer) then begin
  1392. WriteLn(F, 'nil]');
  1393. Writeln(F,'---< ', aName, ' at $', HexStr(@VargSrc), ' >----------------');
  1394. Writeln(F);
  1395. Exit;
  1396. end;
  1397. case vType of
  1398. varNull : Write(F, 'Null');
  1399. varSmallInt : Write(F, vSmallInt);
  1400. varInteger : Write(F, vInteger);
  1401. {$ifndef FPUNONE}
  1402. varSingle : Write(F, vSingle);
  1403. varDouble : Write(F, vDouble);
  1404. varCurrency : Write(F, vCurrency);
  1405. varDate : Write(F, vDate);
  1406. {$endif}
  1407. varOleStr : Write(F, WideString(Pointer(vOleStr)));
  1408. varError : Write(F, IntToHex(Cardinal(vError), 8));
  1409. varBoolean : Write(F, vBoolean);
  1410. varVariant, varVariant or varByRef : begin
  1411. WriteLn(' dereferencing -> ]');
  1412. DumpVariant(F, aName+'^', PVarData(vPointer)^);
  1413. Exit;
  1414. end;
  1415. varShortInt : Write(F, vShortInt);
  1416. varByte : Write(F, vByte);
  1417. varWord : Write(F, vWord);
  1418. varLongWord : Write(F, vLongWord);
  1419. varInt64 : Write(F, vInt64);
  1420. varQword : Write(F, vQWord);
  1421. varString : Write(F, AnsiString(vString));
  1422. varNull or varByRef : Write(F, 'Null');
  1423. varSmallInt or varByRef : Write(F, PSmallInt(vPointer)^);
  1424. varInteger or varByRef : Write(F, PInteger(vPointer)^);
  1425. {$ifndef FPUNONE}
  1426. varSingle or varByRef : Write(F, PSingle(vPointer)^);
  1427. varDouble or varByRef : Write(F, PDouble(vPointer)^);
  1428. varCurrency or varByRef : Write(F, PCurrency(vPointer)^);
  1429. varDate or varByRef : Write(F, PDate(vPointer)^);
  1430. {$endif}
  1431. varOleStr or varByRef : Write(F, WideString(PPointer(vPointer)^));
  1432. varError or varByRef : Write(F, IntToHex(Cardinal(PLongWord(vPointer)^), 8));
  1433. varBoolean or varByRef : Write(F, PWordBool(vPointer)^);
  1434. varShortInt or varByRef : Write(F, PShortInt(vPointer)^);
  1435. varByte or varByRef : Write(F, PByte(vPointer)^);
  1436. varWord or varByRef : Write(F, PWord(vPointer)^);
  1437. varLongWord or varByRef : Write(F, PLongWord(vPointer)^);
  1438. varInt64 or varByRef : Write(F, PInt64(vPointer)^);
  1439. varQword or varByRef : Write(F, PQWord(vPointer)^);
  1440. varString or varByRef : Write(F, AnsiString(PPointer(vPointer)^));
  1441. else
  1442. Write(F, 'Unsupported');
  1443. end;
  1444. WriteLn(F, ']');
  1445. end;
  1446. end;
  1447. Writeln(F,'---< ', aName, ' at $', HexStr(@VargSrc), ' >----------------');
  1448. Writeln(F);
  1449. end;