variant.inc 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2001 by the Free Pascal development team
  4. This include file contains the implementation for variants
  5. support in FPC as far as it is part of the system unit
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. var
  13. variantmanager : tvariantmanager;
  14. procedure printmissingvariantunit;
  15. begin
  16. writeln(stderr);
  17. writeln(stderr,'Program needs probably the variants unit.');
  18. writeln(stderr,'Include the variants unit in your uses statements');
  19. writeln(stderr,'as one of the first units.');
  20. writeln(stderr);
  21. end;
  22. procedure invalidvariantop;
  23. begin
  24. printmissingvariantunit;
  25. HandleErrorFrame(221,get_frame);
  26. end;
  27. procedure invalidvariantopnovariants;
  28. begin
  29. printmissingvariantunit;
  30. HandleErrorFrame(221,get_frame);
  31. end;
  32. procedure vardisperror;
  33. begin
  34. printmissingvariantunit;
  35. HandleErrorFrame(222,get_frame);
  36. end;
  37. { ---------------------------------------------------------------------
  38. Compiler helper routines.
  39. ---------------------------------------------------------------------}
  40. procedure varclear(var v : tvardata);
  41. begin
  42. if not(v.vtype in [varempty,varerror,varnull]) then
  43. invalidvariantop;
  44. end;
  45. procedure variant_init(var v : tvardata);[Public,Alias:'FPC_VARIANT_INIT'];
  46. begin
  47. { calling the variant manager here is a problem because the static/global variants
  48. are initialized while the variant manager isn't assigned }
  49. fillchar(v,sizeof(variant),0);
  50. end;
  51. procedure variant_clear(var v : tvardata);[Public,Alias:'FPC_VARIANT_CLEAR'];
  52. begin
  53. if assigned(VarClearProc) then
  54. VarClearProc(v);
  55. end;
  56. procedure variant_addref(var v : tvardata);[Public,Alias:'FPC_VARIANT_ADDREF'];
  57. begin
  58. if assigned(VarAddRefProc) then
  59. VarAddRefProc(v);
  60. end;
  61. { using pointers as argument here makes life for the compiler easier }
  62. procedure fpc_variant_copy(d,s : pointer);compilerproc;
  63. begin
  64. if assigned(VarCopyProc) then
  65. VarCopyProc(tvardata(d^),tvardata(s^));
  66. end;
  67. Procedure fpc_write_text_variant(Len : Longint;var f : Text;const v : variant); iocheck; [Public,Alias:'FPC_WRITE_TEXT_VARIANT']; compilerproc;
  68. begin
  69. if (InOutRes<>0) then
  70. exit;
  71. case TextRec(f).mode of
  72. { fmAppend gets changed to fmOutPut in do_open (JM) }
  73. fmOutput:
  74. if len=-1 then
  75. variantmanager.write0variant(f,v)
  76. else
  77. variantmanager.writevariant(f,v,len);
  78. fmInput:
  79. InOutRes:=105
  80. else InOutRes:=103;
  81. end;
  82. end;
  83. procedure fpc_vararray_get(var d : variant;const s : variant;indices : psizeint;len : sizeint);compilerproc;
  84. begin
  85. d:=variantmanager.vararrayget(s,len,indices);
  86. end;
  87. procedure fpc_vararray_put(var d : variant;const s : variant;indices : psizeint;len : sizeint);compilerproc;
  88. begin
  89. variantmanager.vararrayput(d,s,len,indices);
  90. end;
  91. function fpc_variant_to_dynarray(const v : variant;typeinfo : pointer) : pointer;compilerproc;
  92. begin
  93. result:=nil;
  94. variantmanager.vartodynarray(result,v,typeinfo);
  95. end;
  96. function fpc_dynarray_to_variant(dynarr : pointer;typeinfo : pointer) : variant;compilerproc;
  97. begin
  98. variantmanager.varfromdynarray(result,dynarr,typeinfo);
  99. end;
  100. function fpc_variant_to_interface(const v : variant) : iinterface;compilerproc;
  101. begin
  102. variantmanager.vartointf(result,v);
  103. end;
  104. function fpc_interface_to_variant(const i : iinterface) : variant;compilerproc;
  105. begin
  106. variantmanager.varfromintf(result,i);
  107. end;
  108. procedure fpc_dispinvoke_variant(dest : pvardata;const source : tvardata;
  109. calldesc : pcalldesc;params : pointer);
  110. begin
  111. variantmanager.dispinvoke(dest,source,calldesc,params);
  112. end;
  113. { ---------------------------------------------------------------------
  114. Overloaded operators.
  115. ---------------------------------------------------------------------}
  116. { Integer }
  117. operator :=(const source : byte) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  118. begin
  119. Variantmanager.varfromInt(Dest,Source,1);
  120. end;
  121. operator :=(const source : shortint) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  122. begin
  123. Variantmanager.varfromInt(Dest,Source,-1);
  124. end;
  125. operator :=(const source : word) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  126. begin
  127. Variantmanager.varfromInt(Dest,Source,2);
  128. end;
  129. operator :=(const source : smallint) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  130. begin
  131. Variantmanager.varfromInt(Dest,Source,-2);
  132. end;
  133. operator :=(const source : dword) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  134. begin
  135. Variantmanager.varfromInt(Dest,Source,4);
  136. end;
  137. operator :=(const source : longint) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  138. begin
  139. Variantmanager.varfromInt(Dest,Source,-4);
  140. end;
  141. operator :=(const source : qword) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  142. begin
  143. Variantmanager.varfromWord64(Dest,Source);
  144. end;
  145. operator :=(const source : int64) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  146. begin
  147. Variantmanager.varfromInt64(Dest,Source);
  148. end;
  149. { Boolean }
  150. operator :=(const source : boolean) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  151. begin
  152. Variantmanager.varfromBool(Dest,Source);
  153. end;
  154. operator :=(const source : wordbool) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  155. begin
  156. Variantmanager.varfromBool(Dest,Boolean(Source));
  157. end;
  158. operator :=(const source : longbool) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  159. begin
  160. Variantmanager.varfromBool(Dest,Boolean(Source));
  161. end;
  162. { Chars }
  163. operator :=(const source : char) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  164. begin
  165. VariantManager.VarFromPStr(Dest,Source);
  166. end;
  167. operator :=(const source : widechar) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  168. begin
  169. VariantManager.VarFromWStr(Dest,Source);
  170. end;
  171. { Strings }
  172. operator :=(const source : shortstring) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  173. begin
  174. VariantManager.VarFromPStr(Dest,Source);
  175. end;
  176. operator :=(const source : ansistring) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  177. begin
  178. VariantManager.VarFromLStr(Dest,Source);
  179. end;
  180. operator :=(const source : widestring) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  181. begin
  182. VariantManager.VarFromWStr(Dest,Source);
  183. end;
  184. { Floats }
  185. {$ifdef SUPPORT_SINGLE}
  186. operator :=(const source : single) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  187. begin
  188. VariantManager.VarFromReal(Dest,Source);
  189. end;
  190. {$endif SUPPORT_SINGLE}
  191. {$ifdef SUPPORT_DOUBLE}
  192. operator :=(const source : double) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  193. begin
  194. VariantManager.VarFromReal(Dest,Source);
  195. end;
  196. {$endif SUPPORT_DOUBLE}
  197. {$ifdef SUPPORT_EXTENDED}
  198. operator :=(const source : extended) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  199. begin
  200. VariantManager.VarFromReal(Dest,Source);
  201. end;
  202. {$endif SUPPORT_EXTENDED}
  203. {$ifdef SUPPORT_COMP}
  204. Operator :=(const source : comp) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  205. begin
  206. VariantManager.VarFromReal(Dest,Source);
  207. end;
  208. {$endif SUPPORT_COMP}
  209. {$ifndef VER2_0}
  210. Operator :=(const source : real) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  211. begin
  212. VariantManager.VarFromReal(Dest,Source);
  213. end;
  214. {$endif VER2_0}
  215. { Misc. }
  216. operator :=(const source : currency) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  217. begin
  218. VariantManager.VarFromCurr(Dest,Source);
  219. end;
  220. operator :=(const source : tdatetime) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  221. begin
  222. VariantManager.VarFromTDateTime(Dest,Source);
  223. end;
  224. operator :=(const source : terror) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  225. begin
  226. Variantmanager.varfromInt(Dest,Source,-sizeof(terror));
  227. end;
  228. {**********************************************************************
  229. from Variant assignments
  230. **********************************************************************}
  231. { Integer }
  232. operator :=(const source : variant) dest : byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  233. begin
  234. dest:=variantmanager.vartoint(source);
  235. end;
  236. operator :=(const source : variant) dest : shortint;{$ifdef SYSTEMINLINE}inline;{$endif}
  237. begin
  238. dest:=variantmanager.vartoint(source);
  239. end;
  240. operator :=(const source : variant) dest : word;{$ifdef SYSTEMINLINE}inline;{$endif}
  241. begin
  242. dest:=variantmanager.vartoint(source);
  243. end;
  244. operator :=(const source : variant) dest : smallint;{$ifdef SYSTEMINLINE}inline;{$endif}
  245. begin
  246. dest:=variantmanager.vartoint(source);
  247. end;
  248. operator :=(const source : variant) dest : dword;{$ifdef SYSTEMINLINE}inline;{$endif}
  249. begin
  250. dest:=variantmanager.vartoint(source);
  251. end;
  252. operator :=(const source : variant) dest : longint;{$ifdef SYSTEMINLINE}inline;{$endif}
  253. begin
  254. dest:=variantmanager.vartoint(source);
  255. end;
  256. operator :=(const source : variant) dest : qword;{$ifdef SYSTEMINLINE}inline;{$endif}
  257. begin
  258. dest:=variantmanager.vartoword64(source);
  259. end;
  260. operator :=(const source : variant) dest : int64;{$ifdef SYSTEMINLINE}inline;{$endif}
  261. begin
  262. dest:=variantmanager.vartoint64(source);
  263. end;
  264. { Boolean }
  265. operator :=(const source : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  266. begin
  267. dest:=variantmanager.vartobool(source);
  268. end;
  269. operator :=(const source : variant) dest : wordbool;{$ifdef SYSTEMINLINE}inline;{$endif}
  270. begin
  271. dest:=variantmanager.vartobool(source);
  272. end;
  273. operator :=(const source : variant) dest : longbool;{$ifdef SYSTEMINLINE}inline;{$endif}
  274. begin
  275. dest:=variantmanager.vartobool(source);
  276. end;
  277. { Chars }
  278. operator :=(const source : variant) dest : char;{$ifdef SYSTEMINLINE}inline;{$endif}
  279. Var
  280. S : String;
  281. begin
  282. VariantManager.VarToPStr(S,Source);
  283. If Length(S)>0 then
  284. Dest:=S[1];
  285. end;
  286. operator :=(const source : variant) dest : widechar;{$ifdef SYSTEMINLINE}inline;{$endif}
  287. Var
  288. WS : WideString;
  289. begin
  290. VariantManager.VarToWStr(WS,Source);
  291. If Length(WS)>0 then
  292. Dest:=WS[1];
  293. end;
  294. { Strings }
  295. operator :=(const source : variant) dest : shortstring;{$ifdef SYSTEMINLINE}inline;{$endif}
  296. begin
  297. VariantManager.VarToPStr(Dest,Source);
  298. end;
  299. operator :=(const source : variant) dest : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  300. begin
  301. VariantManager.vartolstr(dest,source);
  302. end;
  303. operator :=(const source : variant) dest : widestring;{$ifdef SYSTEMINLINE}inline;{$endif}
  304. begin
  305. variantmanager.vartowstr(dest,source);
  306. end;
  307. { Floats }
  308. {$ifdef SUPPORT_SINGLE}
  309. operator :=(const source : variant) dest : single;{$ifdef SYSTEMINLINE}inline;{$endif}
  310. begin
  311. dest:=variantmanager.vartoreal(source);
  312. end;
  313. {$endif SUPPORT_SINGLE}
  314. {$ifdef SUPPORT_DOUBLE}
  315. operator :=(const source : variant) dest : double;{$ifdef SYSTEMINLINE}inline;{$endif}
  316. begin
  317. dest:=variantmanager.vartoreal(source);
  318. end;
  319. {$endif SUPPORT_DOUBLE}
  320. {$ifdef SUPPORT_EXTENDED}
  321. operator :=(const source : variant) dest : extended;{$ifdef SYSTEMINLINE}inline;{$endif}
  322. begin
  323. dest:=variantmanager.vartoreal(source);
  324. end;
  325. {$endif SUPPORT_EXTENDED}
  326. {$ifdef SUPPORT_COMP}
  327. operator :=(const source : variant) dest : comp;{$ifdef SYSTEMINLINE}inline;{$endif}
  328. begin
  329. dest:=comp(variantmanager.vartoreal(source));
  330. end;
  331. {$endif SUPPORT_COMP}
  332. {$ifndef VER2_0}
  333. operator :=(const source : variant) dest : real;{$ifdef SYSTEMINLINE}inline;{$endif}
  334. begin
  335. dest:=comp(variantmanager.vartoreal(source));
  336. end;
  337. {$endif VER2_0}
  338. { Misc. }
  339. operator :=(const source : variant) dest : currency;{$ifdef SYSTEMINLINE}inline;{$endif}
  340. begin
  341. dest:=variantmanager.vartocurr(source);
  342. end;
  343. operator :=(const source : variant) dest : tdatetime;{$ifdef SYSTEMINLINE}inline;{$endif}
  344. begin
  345. dest:=variantmanager.vartotdatetime(source);
  346. end;
  347. {$ifndef FPC_HASINTERNALOLEVARIANT2VARIANTCAST}
  348. operator :=(const source : olevariant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  349. begin
  350. tvardata(result):=tvardata(source);
  351. end;
  352. {$endif FPC_HASINTERNALOLEVARIANT2VARIANTCAST}
  353. operator :=(const source : variant) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  354. begin
  355. variantmanager.olevarfromvar(dest,source);
  356. end;
  357. operator :=(const source : variant) dest : terror;{$ifdef SYSTEMINLINE}inline;{$endif}
  358. begin
  359. dest:=variantmanager.vartoint(source);
  360. end;
  361. {**********************************************************************
  362. Operators
  363. **********************************************************************}
  364. operator or(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  365. begin
  366. dest:=op1;
  367. variantmanager.varop(dest,op2,opor);
  368. end;
  369. operator and(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  370. begin
  371. dest:=op1;
  372. variantmanager.varop(dest,op2,opand);
  373. end;
  374. operator xor(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  375. begin
  376. dest:=op1;
  377. variantmanager.varop(dest,op2,opxor);
  378. end;
  379. operator not(const op : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  380. begin
  381. dest:=op;
  382. variantmanager.varnot(dest);
  383. end;
  384. operator shl(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  385. begin
  386. dest:=op1;
  387. variantmanager.varop(dest,op2,opshiftleft);
  388. end;
  389. operator shr(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  390. begin
  391. dest:=op1;
  392. variantmanager.varop(dest,op2,opshiftright);
  393. end;
  394. operator +(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  395. begin
  396. dest:=op1;
  397. variantmanager.varop(dest,op2,opadd);
  398. end;
  399. operator -(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  400. begin
  401. dest:=op1;
  402. variantmanager.varop(dest,op2,opsubtract);
  403. end;
  404. operator *(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  405. begin
  406. dest:=op1;
  407. variantmanager.varop(dest,op2,opmultiply);
  408. end;
  409. operator /(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  410. begin
  411. dest:=op1;
  412. variantmanager.varop(dest,op2,opdivide);
  413. end;
  414. operator **(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  415. begin
  416. dest:=op1;
  417. variantmanager.varop(dest,op2,oppower);
  418. end;
  419. operator div(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  420. begin
  421. dest:=op1;
  422. variantmanager.varop(dest,op2,opintdivide);
  423. end;
  424. operator mod(const op1,op2 : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  425. begin
  426. dest:=op1;
  427. variantmanager.varop(dest,op2,opmodulus);
  428. end;
  429. operator -(const op : variant) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
  430. begin
  431. dest:=op;
  432. variantmanager.varneg(dest);
  433. end;
  434. operator =(const op1,op2 : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  435. begin
  436. dest:=variantmanager.cmpop(op1,op2,opcmpeq);
  437. end;
  438. operator <(const op1,op2 : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  439. begin
  440. dest:=variantmanager.cmpop(op1,op2,opcmplt);
  441. end;
  442. operator >(const op1,op2 : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  443. begin
  444. dest:=variantmanager.cmpop(op1,op2,opcmpgt);
  445. end;
  446. operator >=(const op1,op2 : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  447. begin
  448. dest:=variantmanager.cmpop(op1,op2,opcmpge);
  449. end;
  450. operator <=(const op1,op2 : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  451. begin
  452. dest:=variantmanager.cmpop(op1,op2,opcmplt);
  453. end;
  454. procedure VarArrayRedim(var A: Variant; HighBound: SizeInt);
  455. begin
  456. variantmanager.vararrayredim(a,highbound);
  457. end;
  458. procedure VarCast(var dest : variant;const source : variant;vartype : longint);
  459. begin
  460. variantmanager.varcast(dest,source,vartype);
  461. end;
  462. {**********************************************************************
  463. from OLEVariant assignments
  464. **********************************************************************}
  465. { Integer }
  466. operator :=(const source : olevariant) dest : byte;{$ifdef SYSTEMINLINE}inline;{$endif}
  467. begin
  468. { cast away olevar to var conversion and avoid
  469. endless recursion }
  470. dest:=variantmanager.vartoint(variant(tvardata(source)));
  471. end;
  472. operator :=(const source : olevariant) dest : shortint;{$ifdef SYSTEMINLINE}inline;{$endif}
  473. begin
  474. dest:=variantmanager.vartoint(variant(tvardata(source)));
  475. end;
  476. operator :=(const source : olevariant) dest : word;{$ifdef SYSTEMINLINE}inline;{$endif}
  477. begin
  478. dest:=variantmanager.vartoint(variant(tvardata(source)));
  479. end;
  480. operator :=(const source : olevariant) dest : smallint;{$ifdef SYSTEMINLINE}inline;{$endif}
  481. begin
  482. dest:=variantmanager.vartoint(variant(tvardata(source)));
  483. end;
  484. operator :=(const source : olevariant) dest : dword;{$ifdef SYSTEMINLINE}inline;{$endif}
  485. begin
  486. dest:=variantmanager.vartoint(variant(tvardata(source)));
  487. end;
  488. operator :=(const source : olevariant) dest : longint;{$ifdef SYSTEMINLINE}inline;{$endif}
  489. begin
  490. dest:=variantmanager.vartoint(variant(tvardata(source)));
  491. end;
  492. operator :=(const source : olevariant) dest : qword;{$ifdef SYSTEMINLINE}inline;{$endif}
  493. begin
  494. dest:=variantmanager.vartoint64(variant(tvardata(source)));
  495. end;
  496. operator :=(const source : olevariant) dest : int64;{$ifdef SYSTEMINLINE}inline;{$endif}
  497. begin
  498. dest:=variantmanager.vartoword64(variant(tvardata(source)));
  499. end;
  500. { Boolean }
  501. operator :=(const source : olevariant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
  502. begin
  503. dest:=variantmanager.vartobool(variant(tvardata(source)));
  504. end;
  505. operator :=(const source : olevariant) dest : wordbool;{$ifdef SYSTEMINLINE}inline;{$endif}
  506. begin
  507. dest:=variantmanager.vartobool(variant(tvardata(source)));
  508. end;
  509. operator :=(const source : olevariant) dest : longbool;{$ifdef SYSTEMINLINE}inline;{$endif}
  510. begin
  511. dest:=variantmanager.vartobool(variant(tvardata(source)));
  512. end;
  513. { Chars }
  514. operator :=(const source : olevariant) dest : char;{$ifdef SYSTEMINLINE}inline;{$endif}
  515. var
  516. S : String;
  517. begin
  518. VariantManager.VarToPStr(S,Source);
  519. If Length(S)>0 then
  520. Dest:=S[1]
  521. else
  522. Dest:=#0;
  523. end;
  524. operator :=(const source : olevariant) dest : widechar;{$ifdef SYSTEMINLINE}inline;{$endif}
  525. Var
  526. WS : WideString;
  527. begin
  528. VariantManager.VarToWStr(WS,Source);
  529. If Length(WS)>0 then
  530. Dest:=WS[1]
  531. else
  532. Dest:=#0;
  533. end;
  534. { Strings }
  535. operator :=(const source : olevariant) dest : shortstring;{$ifdef SYSTEMINLINE}inline;{$endif}
  536. begin
  537. variantmanager.vartopstr(dest,variant(tvardata(source)));
  538. end;
  539. operator :=(const source : olevariant) dest : ansistring;{$ifdef SYSTEMINLINE}inline;{$endif}
  540. begin
  541. variantmanager.vartolstr(dest,variant(tvardata(source)));
  542. end;
  543. operator :=(const source : olevariant) dest : widestring;{$ifdef SYSTEMINLINE}inline;{$endif}
  544. begin
  545. variantmanager.vartowstr(dest,variant(tvardata(source)));
  546. end;
  547. { Floats }
  548. {$ifdef SUPPORT_SINGLE}
  549. operator :=(const source : olevariant) dest : single;{$ifdef SYSTEMINLINE}inline;{$endif}
  550. begin
  551. dest:=variantmanager.vartoreal(variant(tvardata(source)));
  552. end;
  553. {$endif SUPPORT_SINGLE}
  554. {$ifdef SUPPORT_DOUBLE}
  555. operator :=(const source : olevariant) dest : double;{$ifdef SYSTEMINLINE}inline;{$endif}
  556. begin
  557. dest:=variantmanager.vartoreal(variant(tvardata(source)));
  558. end;
  559. {$endif SUPPORT_DOUBLE}
  560. {$ifdef SUPPORT_EXTENDED}
  561. operator :=(const source : olevariant) dest : extended;{$ifdef SYSTEMINLINE}inline;{$endif}
  562. begin
  563. dest:=variantmanager.vartoreal(variant(tvardata(source)));
  564. end;
  565. {$endif SUPPORT_EXTENDED}
  566. {$ifdef SUPPORT_COMP}
  567. operator :=(const source : olevariant) dest : comp;{$ifdef SYSTEMINLINE}inline;{$endif}
  568. begin
  569. dest:=variantmanager.vartoreal(variant(tvardata(source)));
  570. end;
  571. {$endif SUPPORT_COMP}
  572. {$ifndef VER2_0}
  573. operator :=(const source : olevariant) dest : real;{$ifdef SYSTEMINLINE}inline;{$endif}
  574. begin
  575. dest:=variantmanager.vartoreal(variant(tvardata(source)));
  576. end;
  577. {$endif VER2_0}
  578. { Misc. }
  579. operator :=(const source : olevariant) dest : currency;{$ifdef SYSTEMINLINE}inline;{$endif}
  580. begin
  581. dest:=variantmanager.vartocurr(variant(tvardata(source)));
  582. end;
  583. operator :=(const source : olevariant) dest : tdatetime;{$ifdef SYSTEMINLINE}inline;{$endif}
  584. begin
  585. dest:=variantmanager.vartotdatetime(variant(tvardata(source)));
  586. end;
  587. operator :=(const source : olevariant) dest : terror;{$ifdef SYSTEMINLINE}inline;{$endif}
  588. begin
  589. dest:=variantmanager.vartoint(variant(tvardata(source)));
  590. end;
  591. {**********************************************************************
  592. to OLEVariant assignments
  593. **********************************************************************}
  594. operator :=(const source : byte) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  595. begin
  596. variantmanager.olevarfromint(dest,source,1);
  597. end;
  598. operator :=(const source : shortint) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  599. begin
  600. variantmanager.olevarfromint(dest,source,-1);
  601. end;
  602. operator :=(const source : word) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  603. begin
  604. variantmanager.olevarfromint(dest,source,2);
  605. end;
  606. operator :=(const source : smallint) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  607. begin
  608. variantmanager.olevarfromint(dest,source,-2);
  609. end;
  610. operator :=(const source : dword) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  611. begin
  612. variantmanager.olevarfromint(dest,source,4);
  613. end;
  614. operator :=(const source : longint) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  615. begin
  616. variantmanager.olevarfromint(dest,source,-4);
  617. end;
  618. operator :=(const source : qword) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  619. begin
  620. variantmanager.olevarfromint(dest,source,8);
  621. end;
  622. operator :=(const source : int64) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  623. begin
  624. variantmanager.olevarfromint(dest,source,-8);
  625. end;
  626. { Boolean }
  627. operator :=(const source : boolean) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  628. begin
  629. variantmanager.varfromBool(variant(tvardata(dest)),Source);
  630. end;
  631. operator :=(const source : wordbool) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  632. begin
  633. variantmanager.varfromBool(variant(tvardata(Dest)),Source);
  634. end;
  635. operator :=(const source : longbool) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  636. begin
  637. variantmanager.varfromBool(variant(tvardata(Dest)),Source);
  638. end;
  639. { Chars }
  640. operator :=(const source : char) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  641. begin
  642. variantmanager.olevarfrompstr(dest,source);
  643. end;
  644. operator :=(const source : widechar) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  645. begin
  646. variantmanager.varfromwstr(variant(tvardata(dest)),source);
  647. end;
  648. { Strings }
  649. operator :=(const source : shortstring) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  650. begin
  651. variantmanager.olevarfrompstr(dest,source);
  652. end;
  653. operator :=(const source : ansistring) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  654. begin
  655. variantmanager.olevarfromlstr(dest,source);
  656. end;
  657. operator :=(const source : widestring) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  658. begin
  659. variantmanager.varfromwstr(variant(tvardata(dest)),source);
  660. end;
  661. { Floats }
  662. {$ifdef SUPPORT_SINGLE}
  663. operator :=(const source : single) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  664. begin
  665. variantmanager.varfromreal(variant(tvardata(dest)),source);
  666. end;
  667. {$endif SUPPORT_SINGLE}
  668. {$ifdef SUPPORT_DOUBLE}
  669. operator :=(const source : double) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  670. begin
  671. variantmanager.varfromreal(variant(tvardata(dest)),source);
  672. end;
  673. {$endif SUPPORT_DOUBLE}
  674. {$ifdef SUPPORT_EXTENDED}
  675. operator :=(const source : extended) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  676. begin
  677. variantmanager.varfromreal(variant(tvardata(dest)),source);
  678. end;
  679. {$endif SUPPORT_EXTENDED}
  680. {$ifdef SUPPORT_COMP}
  681. operator :=(const source : comp) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  682. begin
  683. variantmanager.varfromreal(variant(tvardata(dest)),source);
  684. end;
  685. {$endif SUPPORT_COMP}
  686. {$ifndef VER2_0}
  687. operator :=(const source : real) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  688. begin
  689. variantmanager.varfromreal(variant(tvardata(dest)),source);
  690. end;
  691. {$endif VER2_0}
  692. { Misc. }
  693. operator :=(const source : currency) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  694. begin
  695. variantmanager.varfromcurr(variant(tvardata(dest)),source);
  696. end;
  697. operator :=(const source : tdatetime) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  698. begin
  699. variantmanager.varfromtdatetime(variant(tvardata(dest)),source);
  700. end;
  701. operator :=(const source : terror) dest : olevariant;{$ifdef SYSTEMINLINE}inline;{$endif}
  702. begin
  703. variantmanager.olevarfromint(dest,source,-sizeof(terror));
  704. end;
  705. {**********************************************************************
  706. Variant manager functions
  707. **********************************************************************}
  708. procedure GetVariantManager(var VarMgr: TVariantManager);
  709. begin
  710. VarMgr:=VariantManager;
  711. end;
  712. procedure SetVariantManager(const VarMgr: TVariantManager);
  713. begin
  714. VariantManager:=VarMgr;
  715. end;
  716. function IsVariantManagerSet: Boolean;
  717. var
  718. i : longint;
  719. begin
  720. I:=0;
  721. Result:=True;
  722. While Result and (I<(sizeof(tvariantmanager) div sizeof(pointer))-1) do
  723. begin
  724. Result:=(PPointer(@variantmanager)+i)^<>Pointer(@invalidvariantop);
  725. Inc(I);
  726. end;
  727. end;
  728. procedure initvariantmanager;
  729. var
  730. i : longint;
  731. begin
  732. VarDispProc:=@vardisperror;
  733. DispCallByIDProc:=@vardisperror;
  734. tvardata(Unassigned).VType:=varEmpty;
  735. tvardata(Null).VType:=varNull;
  736. for i:=0 to (sizeof(tvariantmanager) div sizeof(pointer))-1 do
  737. (ppointer(@variantmanager)+i)^:=@invalidvariantopnovariants;
  738. pointer(variantmanager.varclear):=@varclear
  739. end;