Quick.Value.pas 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. { ***************************************************************************
  2. Copyright (c) 2016-2020 Kike Pérez
  3. Unit : Quick.Value
  4. Description : Autofree value record
  5. Author : Kike Pérez
  6. Version : 1.5
  7. Created : 07/01/2019
  8. Modified : 20/04/2020
  9. This file is part of QuickLib: https://github.com/exilon/QuickLib
  10. ***************************************************************************
  11. Licensed under the Apache License, Version 2.0 (the "License");
  12. you may not use this file except in compliance with the License.
  13. You may obtain a copy of the License at
  14. http://www.apache.org/licenses/LICENSE-2.0
  15. Unless required by applicable law or agreed to in writing, software
  16. distributed under the License is distributed on an "AS IS" BASIS,
  17. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. See the License for the specific language governing permissions and
  19. limitations under the License.
  20. *************************************************************************** }
  21. unit Quick.Value;
  22. {$i QuickLib.inc}
  23. interface
  24. uses
  25. SysUtils,
  26. Variants;
  27. type
  28. TValueDataType = (dtNull, dtString, dtAnsiString, dtWideString, dtInteger, dtInt64, dtDouble, dtExtended, dtDateTime, dtBoolean, dtObject, dtOwnedObject,
  29. dtPointer, dtClass, dtInterface, dtRecord, dtArray, dtVariant);
  30. TValueData = class(TInterfacedObject);
  31. IValueString = interface
  32. ['{CECEF8BB-5C77-4291-8927-FB090577F27D}']
  33. function GetValue : string;
  34. procedure SetValue(const Value : string);
  35. property Value : string read GetValue write SetValue;
  36. end;
  37. TValueString = class(TValueData,IValueString)
  38. strict private
  39. fData : string;
  40. private
  41. function GetValue : string;
  42. procedure SetValue(const Value : string);
  43. public
  44. constructor Create(const Value : string);
  45. property Value : string read GetValue write SetValue;
  46. end;
  47. {$IFDEF MSWINDOWS}
  48. IValueAnsiString = interface
  49. ['{75775F25-6F7A-49F0-A1E0-BDE1F55EC378}']
  50. function GetValue : AnsiString;
  51. procedure SetValue(const Value : AnsiString);
  52. property Value : AnsiString read GetValue write SetValue;
  53. end;
  54. TValueAnsiString = class(TValueData,IValueAnsiString)
  55. strict private
  56. fData : AnsiString;
  57. private
  58. function GetValue : AnsiString;
  59. procedure SetValue(const Value : AnsiString);
  60. public
  61. constructor Create(const Value : AnsiString);
  62. property Value : AnsiString read GetValue write SetValue;
  63. end;
  64. IValueWideString = interface
  65. ['{9094B9CF-46AE-4FE0-AE1D-6E6CDABDAF36}']
  66. function GetValue : WideString;
  67. procedure SetValue(const Value : WideString);
  68. property Value : WideString read GetValue write SetValue;
  69. end;
  70. TValueWideString = class(TValueData,IValueWideString)
  71. strict private
  72. fData : WideString;
  73. private
  74. function GetValue : WideString;
  75. procedure SetValue(const Value : WideString);
  76. public
  77. constructor Create(const Value : WideString);
  78. property Value : WideString read GetValue write SetValue;
  79. end;
  80. {$ENDIF}
  81. IValueInteger = interface
  82. ['{5AB05017-C6F3-49BA-A92C-ECCA252B3E1D}']
  83. function GetValue : Int64;
  84. procedure SetValue(const Value : Int64);
  85. property Value : Int64 read GetValue write SetValue;
  86. end;
  87. { TValueInteger }
  88. TValueInteger= class(TValueData,IValueInteger)
  89. strict private
  90. fData : Int64;
  91. private
  92. function GetValue : Int64;
  93. procedure SetValue(const Value : Int64);
  94. public
  95. constructor Create(const Value : Int64);
  96. property Value : Int64 read GetValue write SetValue;
  97. end;
  98. IValueExtended = interface
  99. ['{D341182F-D4E5-4C07-9E03-68DA118B90B1}']
  100. function GetValue : Extended;
  101. procedure SetValue(const Value : Extended);
  102. property Value : Extended read GetValue write SetValue;
  103. end;
  104. TValueExtended = class(TValueData,IValueExtended)
  105. strict private
  106. fData : Extended;
  107. private
  108. function GetValue : Extended;
  109. procedure SetValue(const Value : Extended);
  110. public
  111. constructor Create(const Value : Extended);
  112. property Value : Extended read GetValue write SetValue;
  113. end;
  114. IValueObject = interface
  115. ['{5828FABC-6C5D-4954-941E-B3580F918A8B}']
  116. function GetValue : TObject;
  117. procedure SetValue(const Value : TObject);
  118. property Value : TObject read GetValue write SetValue;
  119. end;
  120. TValueObject = class(TValueData,IValueObject)
  121. strict private
  122. fData : TObject;
  123. private
  124. function GetValue : TObject;
  125. procedure SetValue(const Value : TObject);
  126. public
  127. constructor Create(const Value : TObject);
  128. property Value : TObject read GetValue write SetValue;
  129. end;
  130. IValuePointer = interface
  131. ['{9FE4E499-C487-4D24-8190-14FF3F9FE86B}']
  132. function GetValue : Pointer;
  133. procedure SetValue(const Value : Pointer);
  134. property Value : Pointer read GetValue write SetValue;
  135. end;
  136. TValuePointer = class(TValueData,IValuePointer)
  137. strict private
  138. fData : Pointer;
  139. private
  140. function GetValue : Pointer;
  141. procedure SetValue(const Value : Pointer);
  142. public
  143. constructor Create(const Value : Pointer);
  144. property Value : Pointer read GetValue write SetValue;
  145. end;
  146. IValueVariant = interface
  147. ['{8B1F8469-B872-47AD-83BB-F51920012943}']
  148. function GetValue : Variant;
  149. procedure SetValue(const Value : Variant);
  150. property Value : Variant read GetValue write SetValue;
  151. end;
  152. TValueVariant = class(TValueData,IValueVariant)
  153. strict private
  154. fData : Variant;
  155. private
  156. function GetValue : Variant;
  157. procedure SetValue(const Value : Variant);
  158. public
  159. constructor Create(const Value : Variant);
  160. property Value : Variant read GetValue write SetValue;
  161. end;
  162. { TFlexValue }
  163. TFlexValue = record
  164. private
  165. {$IFNDEF FPC}
  166. fDataIntf : IInterface;
  167. {$ELSE}
  168. fDataIntf : TValueData;
  169. {$ENDIF}
  170. fDataType : TValueDataType;
  171. function CastToString : string;
  172. {$IFDEF MSWINDOWS}
  173. function CastToAnsiString : AnsiString;
  174. function CastToWideString : WideString;
  175. {$ENDIF}
  176. function CastToBoolean: Boolean;
  177. function CastToClass: TClass;
  178. function CastToExtended: Extended;
  179. function CastToInt64: Int64;
  180. function CastToInteger: Integer;
  181. function CastToDateTime : TDateTime;
  182. function CastToObject: TObject;
  183. function CastToPointer: Pointer;
  184. function CastToInterface: IInterface;
  185. function CastToVariant: Variant;
  186. function CastToCardinal : Cardinal;
  187. function CastToVarRec: TVarRec;
  188. procedure SetAsString(const Value : string);
  189. procedure SetAsVarRec(const Value: TVarRec);
  190. {$IFDEF MSWINDOWS}
  191. procedure SetAsAnsiString(const Value : AnsiString);
  192. procedure SetAsWideString(const Value : WideString);
  193. {$ENDIF}
  194. procedure SetAsBoolean(const Value: Boolean);
  195. procedure SetAsClass(const Value: TClass);
  196. procedure SetAsExtended(const Value: Extended);
  197. procedure SetAsInt64(const Value: Int64);
  198. procedure SetAsInteger(const Value: Integer);
  199. procedure SetAsObject(const Value: TObject);
  200. procedure SetAsPointer(const Value: Pointer);
  201. procedure SetAsDateTime(const Value : TDateTime);
  202. procedure SetAsVariant(const Value: Variant);
  203. procedure SetAsCardinal(const Value : Cardinal);
  204. procedure SetAsInterface(const Value: IInterface);
  205. public
  206. constructor Create(const Value: TVarRec);
  207. {$IFNDEF FPC}
  208. property Data : IInterface read fDataIntf;
  209. {$ELSE}
  210. property Data : TValueData read fDataIntf;
  211. {$ENDIF}
  212. property DataType : TValueDataType read fDataType;
  213. {$IFNDEF FPC}
  214. procedure SetAsCustom(aData : IInterface; aType : TValueDataType);
  215. {$ENDIF}
  216. property AsString : string read CastToString write SetAsString;
  217. {$IFDEF MSWINDOWS}
  218. property AsAnsiString : AnsiString read CastToAnsiString write SetAsAnsiString;
  219. property AsWideString : WideString read CastToWideString write SetAsWideString;
  220. {$ENDIF}
  221. property AsInteger : Integer read CastToInteger write SetAsInteger;
  222. property AsInt64 : Int64 read CastToInt64 write SetAsInt64;
  223. property AsExtended : Extended read CastToExtended write SetAsExtended;
  224. property AsBoolean : Boolean read CastToBoolean write SetAsBoolean;
  225. property AsPointer : Pointer read CastToPointer write SetAsPointer;
  226. property AsClass : TClass read CastToClass write SetAsClass;
  227. property AsInterface : IInterface read CastToInterface write SetAsInterface;
  228. property AsObject : TObject read CastToObject write SetAsObject;
  229. property AsVariant : Variant read CastToVariant write SetAsVariant;
  230. property AsCardinal : Cardinal read CastToCardinal write SetAsCardinal;
  231. property AsDateTime : TDateTime read CastToDateTime write SetAsDateTime;
  232. property AsVarRec : TVarRec read CastToVarRec write SetAsVarRec;
  233. //function AsType<T> : T;
  234. function IsNullOrEmpty : Boolean; inline;
  235. function IsString : Boolean; inline;
  236. function IsInteger : Boolean; inline;
  237. function IsFloating : Boolean; inline;
  238. function IsDateTime : Boolean; inline;
  239. function IsBoolean : Boolean; inline;
  240. function IsInterface : Boolean; inline;
  241. function IsObject : Boolean; inline;
  242. function IsPointer : Boolean; inline;
  243. function IsVariant : Boolean; inline;
  244. function IsArray : Boolean; inline;
  245. function IsRealInteger : Boolean;
  246. function IsRealExtended : Boolean;
  247. procedure Clear; inline;
  248. procedure _AddRef; inline;
  249. procedure _Release; inline;
  250. class operator Implicit(const Value : TFlexValue) : string;
  251. class operator Implicit(Value : TFlexValue) : Integer;
  252. class operator Implicit(Value : TFlexValue) : Int64;
  253. class operator Implicit(Value : TFlexValue) : Extended;
  254. class operator Implicit(Value : TFlexValue) : TDateTime;
  255. class operator Implicit(Value : TFlexValue) : Boolean;
  256. class operator Implicit(Value : TFlexValue) : TClass;
  257. class operator Implicit(Value : TFlexValue) : TObject;
  258. class operator Implicit(Value : TFlexValue) : Pointer;
  259. class operator Implicit(Value : TFlexValue) : Variant;
  260. class operator Implicit(Value : TFlexValue) : TVarRec;
  261. class operator Implicit(const Value : string) : TFlexValue;
  262. class operator Implicit(Value : Integer) : TFlexValue;
  263. class operator Implicit(Value : Int64) : TFlexValue;
  264. class operator Implicit(Value : Extended) : TFlexValue;
  265. class operator Implicit(Value : TDateTime) : TFlexValue;
  266. class operator Implicit(Value : Boolean) : TFlexValue;
  267. class operator Implicit(Value : TClass) : TFlexValue;
  268. class operator Implicit(Value : TObject) : TFlexValue;
  269. class operator Implicit(Value : Pointer) : TFlexValue;
  270. class operator Implicit(Value : Variant) : TFlexValue;
  271. class operator Implicit(Value : TVarRec) : TFlexValue;
  272. class operator Equal(a : TFlexValue; b : string) : Boolean;
  273. class operator Equal(a : TFlexValue; b : Integer) : Boolean;
  274. class operator Equal(a : TFlexValue; b : Int64) : Boolean;
  275. class operator Equal(a : TFlexValue; b : Extended) : Boolean;
  276. class operator Equal(a : TFlexValue; b : Boolean) : Boolean;
  277. class operator NotEqual(a : TFlexValue; b : string) : Boolean;
  278. class operator NotEqual(a : TFlexValue; b : Integer) : Boolean;
  279. class operator NotEqual(a : TFlexValue; b : Int64) : Boolean;
  280. class operator NotEqual(a : TFlexValue; b : Extended) : Boolean;
  281. class operator NotEqual(a : TFlexValue; b : Boolean) : Boolean;
  282. class operator GreaterThan(a : TFlexValue; b : Integer) : Boolean;
  283. class operator GreaterThan(a : TFlexValue; b : Int64) : Boolean;
  284. class operator GreaterThan(a : TFlexValue; b : Extended) : Boolean;
  285. class operator GreaterThanOrEqual(a : TFlexValue; b : Integer) : Boolean;
  286. class operator GreaterThanOrEqual(a : TFlexValue; b : Int64) : Boolean;
  287. class operator GreaterThanOrEqual(a : TFlexValue; b : Extended) : Boolean;
  288. class operator LessThan(a : TFlexValue; b : Integer) : Boolean;
  289. class operator LessThan(a : TFlexValue; b : Int64) : Boolean;
  290. class operator LessThan(a : TFlexValue; b : Extended) : Boolean;
  291. class operator LessThanOrEqual(a : TFlexValue; b : Integer) : Boolean;
  292. class operator LessThanOrEqual(a : TFlexValue; b : Int64) : Boolean;
  293. class operator LessThanOrEqual(a : TFlexValue; b : Extended) : Boolean;
  294. end;
  295. PFlexValue = ^TFlexValue;
  296. TFlexPair = record
  297. Name : string;
  298. Value : TFlexValue;
  299. constructor Create(const aName : string; aValue : TFlexValue);
  300. end;
  301. implementation
  302. function TFlexValue.CastToString: string;
  303. begin
  304. try
  305. case fDataType of
  306. dtNull : Result := '';
  307. dtString : Result := (fDataIntf as IValueString).Value;
  308. {$IFDEF MSWINDOWS}
  309. dtAnsiString : Result := string((fDataIntf as IValueAnsiString).Value);
  310. dtWideString : Result := (fDataIntf as IValueWideString).Value;
  311. {$ENDIF}
  312. dtInteger,
  313. dtInt64 : Result := IntToStr(AsInt64);
  314. dtBoolean : Result := BoolToStr(AsBoolean,True);
  315. dtDouble,
  316. dtExtended : Result := FloatToStr(AsExtended);
  317. dtDateTime : Result := DateTimeToStr(AsExtended);
  318. dtVariant : Result := string(AsVariant);
  319. dtClass : Result := AsClass.ClassName;
  320. else raise Exception.Create('DataType not supported');
  321. end;
  322. except
  323. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to String error: %s',[e.message]);
  324. end;
  325. end;
  326. {$IFDEF MSWINDOWS}
  327. function TFlexValue.CastToAnsiString: AnsiString;
  328. begin
  329. try
  330. case fDataType of
  331. dtNull : Result := '';
  332. dtString : Result := AnsiString((fDataIntf as IValueString).Value);
  333. dtAnsiString : Result := (fDataIntf as IValueAnsiString).Value;
  334. dtWideString : Result := AnsiString((fDataIntf as IValueWideString).Value);
  335. dtInteger,
  336. dtInt64 : Result := AnsiString(IntToStr(AsInt64));
  337. dtBoolean : Result := AnsiString(BoolToStr(AsBoolean,True));
  338. dtDouble,
  339. dtExtended : Result := AnsiString(FloatToStr(AsExtended));
  340. dtDateTime : Result := AnsiString(DateTimeToStr(AsExtended));
  341. dtVariant : Result := AnsiString(AsVariant);
  342. else raise Exception.Create('DataType not supported');
  343. end;
  344. except
  345. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to AnsiString error: %s',[e.message]);
  346. end;
  347. end;
  348. function TFlexValue.CastToWideString: WideString;
  349. begin
  350. try
  351. case fDataType of
  352. dtNull : Result := '';
  353. dtString : Result := Widestring((fDataIntf as IValueString).Value);
  354. {$IFDEF MSWINDOWS}
  355. dtAnsiString : Result := Widestring((fDataIntf as IValueAnsiString).Value);
  356. dtWideString : Result := (fDataIntf as IValueWideString).Value;
  357. {$ENDIF}
  358. dtInteger,
  359. dtInt64 : Result := Widestring(IntToStr(AsInt64));
  360. dtBoolean : Result := Widestring(BoolToStr(AsBoolean,True));
  361. dtDouble,
  362. dtExtended : Result := Widestring(FloatToStr(AsExtended));
  363. dtDateTime : Result := Widestring(DateTimeToStr(AsExtended));
  364. dtVariant : Result := Widestring(AsVariant);
  365. else raise Exception.Create('DataType not supported');
  366. end;
  367. except
  368. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to WideString error: %s',[e.message]);
  369. end;
  370. end;
  371. {$ENDIF}
  372. function TFlexValue.CastToBoolean: Boolean;
  373. begin
  374. try
  375. case fDataType of
  376. dtNull : Result := False;
  377. dtString : Result := StrToBool((fDataIntf as IValueString).Value);
  378. {$IFDEF MSWINDOWS}
  379. dtAnsiString : Result := StrToBool(string((fDataIntf as IValueAnsiString).Value));
  380. dtWideString : Result := StrToBool((fDataIntf as IValueWideString).Value);
  381. {$ENDIF}
  382. dtInteger,
  383. dtInt64 :
  384. begin
  385. if (fDataIntf as IValueInteger).Value = 1 then Result := True
  386. else if (fDataIntf as IValueInteger).Value = 0 then Result := False
  387. else raise Exception.Create('Integer value not in 0-1 range');
  388. end;
  389. dtBoolean : Result := Boolean((fDataIntf as IValueInteger).Value);
  390. dtVariant : Result := Boolean(AsVariant);
  391. else raise Exception.Create('DataType not supported');
  392. end;
  393. except
  394. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Boolean error: %s',[e.message]);
  395. end;
  396. end;
  397. function TFlexValue.CastToCardinal: Cardinal;
  398. begin
  399. Result := AsInt64;
  400. end;
  401. function TFlexValue.CastToClass: TClass;
  402. begin
  403. try
  404. case fDataType of
  405. dtNull : Result := nil;
  406. dtClass : Result := (fDataIntf as TValuePointer).Value;
  407. else raise Exception.Create('DataType not supported');
  408. end;
  409. except
  410. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to TClass error: %s',[e.message]);
  411. end;
  412. end;
  413. function TFlexValue.CastToDateTime: TDateTime;
  414. begin
  415. try
  416. case fDataType of
  417. dtNull : Result := 0.0;
  418. dtString : Result := StrToDateTime((fDataIntf as IValueString).Value);
  419. {$IFDEF MSWINDOWS}
  420. dtAnsiString : Result := StrToDateTime(string((fDataIntf as IValueAnsiString).Value));
  421. dtWideString : Result := StrToDateTime((fDataIntf as IValueWideString).Value);
  422. {$ENDIF}
  423. dtInteger,
  424. dtInt64 : Result := FileDateToDateTime(AsInt64);
  425. dtDouble,
  426. dtExtended,
  427. dtDateTime : Result := (fDataIntf as IValueExtended).Value;
  428. dtVariant : Result := Extended(AsVariant);
  429. else raise Exception.Create('DataType not supported');
  430. end;
  431. except
  432. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Extended error: %s',[e.message]);
  433. end;
  434. end;
  435. function TFlexValue.CastToExtended: Extended;
  436. begin
  437. try
  438. case fDataType of
  439. dtNull : Result := 0.0;
  440. dtString : Result := StrToFloat((fDataIntf as IValueString).Value);
  441. {$IFDEF MSWINDOWS}
  442. dtAnsiString : Result := StrToFloat(string((fDataIntf as IValueAnsiString).Value));
  443. dtWideString : Result := StrToFloat((fDataIntf as IValueWideString).Value);
  444. {$ENDIF}
  445. dtInteger,
  446. dtInt64 : Result := AsInt64;
  447. dtBoolean : Result := AsInt64;
  448. dtDouble,
  449. dtExtended,
  450. dtDateTime : Result := (fDataIntf as IValueExtended).Value;
  451. dtVariant : Result := Extended(AsVariant);
  452. else raise Exception.Create('DataType not supported');
  453. end;
  454. except
  455. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Extended error: %s',[e.message]);
  456. end;
  457. end;
  458. function TFlexValue.CastToInt64: Int64;
  459. begin
  460. try
  461. case fDataType of
  462. dtNull : Result := 0;
  463. dtString : Result := StrToInt((fDataIntf as IValueString).Value);
  464. {$IFDEF MSWINDOWS}
  465. dtAnsiString : Result := StrToInt(string((fDataIntf as IValueAnsiString).Value));
  466. dtWideString : Result := StrToInt((fDataIntf as IValueWideString).Value);
  467. {$ENDIF}
  468. dtInteger,
  469. dtInt64 : Result := (fDataIntf as IValueInteger).Value;
  470. dtBoolean : Result := Integer(AsBoolean);
  471. dtDateTime : Result := DateTimeToFileDate((fDataIntf as IValueExtended).Value);
  472. dtVariant : Result := Integer(AsVariant);
  473. else raise Exception.Create('DataType not supported');
  474. end;
  475. except
  476. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Integer error: %s',[e.message]);
  477. end;
  478. end;
  479. function TFlexValue.CastToInteger: Integer;
  480. begin
  481. Result := AsInt64;
  482. end;
  483. function TFlexValue.CastToObject: TObject;
  484. begin
  485. try
  486. case fDataType of
  487. dtObject,
  488. dtOwnedObject : Result := (fDataIntf as IValueObject).Value;
  489. {$IFNDEF FPC}
  490. dtPointer : Result := TObject((fDataIntf as IValueObject).Value);
  491. {$ELSE}
  492. dtPointer : Result := TObject((fDataIntf as IValuePointer).Value);
  493. {$ENDIF}
  494. dtNull : Result := nil;
  495. else raise Exception.Create('DataType not supported');
  496. end;
  497. except
  498. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Object error: %s',[e.message]);
  499. end;
  500. end;
  501. function TFlexValue.CastToPointer: Pointer;
  502. begin
  503. try
  504. case fDataType of
  505. dtObject,
  506. dtOwnedObject : Result := Pointer((fDataIntf as IValueObject).Value);
  507. dtPointer : Result := (fDataIntf as IValuePointer).Value;
  508. dtNull : Result := nil;
  509. else raise Exception.Create('DataType not supported');
  510. end;
  511. except
  512. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Pointer error: %s',[e.message]);
  513. end;
  514. end;
  515. function TFlexValue.CastToVariant: Variant;
  516. begin
  517. try
  518. case fDataType of
  519. dtNull : Result := Variants.Null;
  520. dtBoolean : Result := AsVariant;
  521. {$IFDEF MSWINDOWS}
  522. dtAnsiString : Result := string((fDataIntf as IValueAnsiString).Value);
  523. dtWideString : Result := (fDataIntf as IValueWideString).Value;
  524. {$ENDIF}
  525. dtString : Result := (fDataIntf as IValueString).Value;
  526. dtInteger,
  527. dtInt64 : Result := (fDataIntf as IValueInteger).Value;
  528. dtVariant : Result := (fDataIntf as IValueVariant).Value;
  529. else raise Exception.Create('DataType not supported');
  530. end;
  531. except
  532. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Variant error: %s',[e.message]);
  533. end;
  534. end;
  535. function TFlexValue.CastToVarRec: TVarRec;
  536. begin
  537. try
  538. case fDataType of
  539. dtNull : Result.VPointer := nil;
  540. dtBoolean : Result.VBoolean := AsBoolean;
  541. {$IFDEF MSWINDOWS}
  542. dtAnsiString : Result.VAnsiString := Pointer((fDataIntf as IValueAnsiString).Value);
  543. dtWideString : Result.VWideString := Pointer((fDataIntf as IValueWideString).Value);
  544. {$ENDIF}
  545. {$IFNDEF NEXTGEN}
  546. dtString : Result.VString := Pointer((fDataIntf as IValueString).Value);
  547. {$ELSE}
  548. dtString : Result.VUnicodeString := Pointer((fDataIntf as IValueString));
  549. {$ENDIF}
  550. dtInteger : Result.VInteger := (fDataIntf as IValueInteger).Value;
  551. dtInt64 : Result.VInt64 := Pointer((fDataIntf as IValueInteger).Value);
  552. //dtVariant : Result.VVariant := ^fDataIntf as IValueVariant).Value;
  553. dtObject : Result.VObject := AsObject;
  554. dtPointer : Result.VPointer := AsPointer;
  555. else raise Exception.Create('DataType not supported');
  556. end;
  557. except
  558. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to TVarRec error: %s',[e.message]);
  559. end;
  560. end;
  561. function TFlexValue.CastToInterface: IInterface;
  562. begin
  563. try
  564. case fDataType of
  565. dtNull : Result := nil;
  566. dtInterface : Result := fDataIntf;
  567. dtPointer : Result := IInterface(fDataIntf);
  568. else raise Exception.Create('DataType not supported');
  569. end;
  570. except
  571. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Interface error: %s',[e.message]);
  572. end;
  573. end;
  574. procedure TFlexValue.Clear;
  575. begin
  576. if Pointer(fDataIntf) <> nil then fDataIntf := nil;
  577. fDataType := dtNull;
  578. end;
  579. constructor TFlexValue.Create(const Value: TVarRec);
  580. begin
  581. case Value.VType of
  582. {$IFNDEF NEXTGEN}
  583. vtString : AsString := string(Value.VString^);
  584. vtChar : AsString := string(Value.VChar);
  585. {$ENDIF}
  586. {$IFDEF MSWINDOWS}
  587. vtAnsiString : AsAnsiString := AnsiString(Value.VAnsiString);
  588. vtWideString : AsWideString := WideString(Value.VWideString);
  589. {$ENDIF}
  590. {$IFDEF UNICODE}
  591. vtUnicodeString: AsString := string(Value.VUnicodeString);
  592. {$ENDIF UNICODE}
  593. vtInteger : AsInteger := Value.VInteger;
  594. vtInt64 : AsInt64 := Value.VInt64^;
  595. vtExtended : AsExtended := Value.VExtended^;
  596. vtBoolean : AsBoolean := Value.VBoolean;
  597. vtVariant : AsVariant := Value.VVariant^;
  598. vtInterface : AsInterface := IInterface(Value.VInterface);
  599. vtClass : AsClass := Value.VClass;
  600. vtObject : AsObject := Value.VObject;
  601. vtPointer : AsPointer := Value.VPointer;
  602. else raise Exception.Create('DataType not supported by TFlexValue');
  603. end;
  604. {$IFDEF FPC}
  605. fDataIntf._AddRef;
  606. {$ENDIF}
  607. end;
  608. class operator TFlexValue.Implicit(Value: TFlexValue): Boolean;
  609. begin
  610. Result := Value.AsBoolean;
  611. end;
  612. class operator TFlexValue.Implicit(const Value: TFlexValue): string;
  613. begin
  614. Result := Value.AsString;
  615. end;
  616. class operator TFlexValue.Implicit(Value: TFlexValue): TObject;
  617. begin
  618. Result := Value.AsObject;
  619. end;
  620. class operator TFlexValue.Implicit(Value: TFlexValue): Pointer;
  621. begin
  622. Result := Value.AsPointer;
  623. end;
  624. class operator TFlexValue.Implicit(Value: TFlexValue): TDateTime;
  625. begin
  626. Result := Value.AsDateTime;
  627. end;
  628. class operator TFlexValue.Implicit(Value: TFlexValue): TClass;
  629. begin
  630. Result := Value.AsClass;
  631. end;
  632. class operator TFlexValue.Implicit(Value: TFlexValue): Int64;
  633. begin
  634. Result := Value.AsInt64;
  635. end;
  636. class operator TFlexValue.Implicit(Value: TFlexValue): Integer;
  637. begin
  638. Result := Value.AsInteger;
  639. end;
  640. class operator TFlexValue.Implicit(Value: TFlexValue): Extended;
  641. begin
  642. Result := Value.AsExtended;
  643. end;
  644. class operator TFlexValue.Implicit(Value: TFlexValue): Variant;
  645. begin
  646. Result := Value.AsVariant;
  647. end;
  648. class operator TFlexValue.Implicit(Value: TFlexValue): TVarRec;
  649. begin
  650. Result := Value.AsVarRec;
  651. end;
  652. class operator TFlexValue.Implicit(Value: Variant): TFlexValue;
  653. begin
  654. Result.AsVariant := Value;
  655. end;
  656. class operator TFlexValue.Implicit(const Value : string) : TFlexValue;
  657. begin
  658. Result.AsString := Value;
  659. end;
  660. class operator TFlexValue.Implicit(Value : Integer) : TFlexValue;
  661. begin
  662. Result.AsInteger := Value;
  663. end;
  664. class operator TFlexValue.Implicit(Value : Int64) : TFlexValue;
  665. begin
  666. Result.AsInt64 := Value;
  667. end;
  668. class operator TFlexValue.Implicit(Value : Extended) : TFlexValue;
  669. begin
  670. Result.AsExtended := Value;
  671. end;
  672. class operator TFlexValue.Implicit(Value : TDateTime) : TFlexValue;
  673. begin
  674. Result.AsDateTime := Value;
  675. end;
  676. class operator TFlexValue.Implicit(Value : Boolean) : TFlexValue;
  677. begin
  678. Result.AsBoolean := Value;
  679. end;
  680. class operator TFlexValue.Implicit(Value : TClass) : TFlexValue;
  681. begin
  682. Result.AsClass := Value;
  683. end;
  684. class operator TFlexValue.Implicit(Value : TObject) : TFlexValue;
  685. begin
  686. Result.AsObject := Value;
  687. end;
  688. class operator TFlexValue.Implicit(Value : Pointer) : TFlexValue;
  689. begin
  690. Result.AsPointer := Value;
  691. end;
  692. class operator TFlexValue.Implicit(Value: TVarRec): TFlexValue;
  693. begin
  694. Result.AsVarRec := Value;
  695. end;
  696. class operator TFlexValue.Equal(a: TFlexValue; b: string): Boolean;
  697. begin
  698. Result := a.AsString = b;
  699. end;
  700. class operator TFlexValue.Equal(a: TFlexValue; b: Int64): Boolean;
  701. begin
  702. Result := a.AsInt64 = b;
  703. end;
  704. class operator TFlexValue.Equal(a: TFlexValue; b: Extended): Boolean;
  705. begin
  706. Result := a.AsExtended = b;
  707. end;
  708. class operator TFlexValue.Equal(a: TFlexValue; b: Boolean): Boolean;
  709. begin
  710. Result := a.AsBoolean = b;
  711. end;
  712. class operator TFlexValue.Equal(a : TFlexValue; b : Integer) : Boolean;
  713. begin
  714. Result := a.AsInteger = b;
  715. end;
  716. class operator TFlexValue.NotEqual(a: TFlexValue; b: Int64): Boolean;
  717. begin
  718. Result := a.AsInt64 <> b;
  719. end;
  720. class operator TFlexValue.NotEqual(a: TFlexValue; b: Integer): Boolean;
  721. begin
  722. Result := a.AsInteger <> b;
  723. end;
  724. class operator TFlexValue.NotEqual(a: TFlexValue; b: string): Boolean;
  725. begin
  726. Result := a.AsString <> b;
  727. end;
  728. class operator TFlexValue.NotEqual(a: TFlexValue; b: Boolean): Boolean;
  729. begin
  730. Result := a.AsBoolean <> b;
  731. end;
  732. class operator TFlexValue.NotEqual(a: TFlexValue; b: Extended): Boolean;
  733. begin
  734. Result := a.AsExtended <> b;
  735. end;
  736. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Integer): Boolean;
  737. begin
  738. Result := a.AsInteger > b;
  739. end;
  740. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Int64): Boolean;
  741. begin
  742. Result := a.AsInt64 > b;
  743. end;
  744. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Extended): Boolean;
  745. begin
  746. Result := a.AsExtended > b;
  747. end;
  748. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Integer): Boolean;
  749. begin
  750. Result := a.AsInteger >= b;
  751. end;
  752. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Int64): Boolean;
  753. begin
  754. Result := a.AsInt64 >= b;
  755. end;
  756. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Extended): Boolean;
  757. begin
  758. Result := a.AsExtended >= b;
  759. end;
  760. class operator TFlexValue.LessThan(a: TFlexValue; b: Integer): Boolean;
  761. begin
  762. Result := a.AsInteger < b;
  763. end;
  764. class operator TFlexValue.LessThan(a: TFlexValue; b: Int64): Boolean;
  765. begin
  766. Result := a.AsInt64 < b;
  767. end;
  768. class operator TFlexValue.LessThan(a: TFlexValue; b: Extended): Boolean;
  769. begin
  770. Result := a.AsExtended < b;
  771. end;
  772. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b : Integer): Boolean;
  773. begin
  774. Result := a.AsInteger <= b;
  775. end;
  776. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b : Int64): Boolean;
  777. begin
  778. Result := a.AsInt64 <= b;
  779. end;
  780. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b: Extended): Boolean;
  781. begin
  782. Result := a.AsExtended <= b;
  783. end;
  784. function TFlexValue.IsArray: Boolean;
  785. begin
  786. Result := fDataType = dtArray;
  787. end;
  788. function TFlexValue.IsBoolean: Boolean;
  789. begin
  790. Result := fDataType = dtBoolean;
  791. end;
  792. function TFlexValue.IsDateTime: Boolean;
  793. begin
  794. Result := fDataType = dtDateTime;
  795. end;
  796. function TFlexValue.IsFloating: Boolean;
  797. begin
  798. Result := fDataType in [dtDouble,dtExtended];
  799. end;
  800. function TFlexValue.IsInteger: Boolean;
  801. begin
  802. Result := fDataType in [dtInteger,dtInt64];
  803. end;
  804. function TFlexValue.IsInterface: Boolean;
  805. begin
  806. Result := fDataType = dtInterface;
  807. end;
  808. function TFlexValue.IsNullOrEmpty: Boolean;
  809. begin
  810. Result := fDataIntf = nil;
  811. end;
  812. function TFlexValue.IsObject: Boolean;
  813. begin
  814. Result := fDataType = dtObject;
  815. end;
  816. function TFlexValue.IsPointer: Boolean;
  817. begin
  818. Result := fDataType = dtPointer;
  819. end;
  820. function TFlexValue.IsRealExtended: Boolean;
  821. var
  822. i : Extended;
  823. begin
  824. Result := TryStrToFloat(AsString,i);
  825. end;
  826. function TFlexValue.IsRealInteger: Boolean;
  827. var
  828. i : Int64;
  829. begin
  830. Result := TryStrToInt64(AsString,i);
  831. end;
  832. function TFlexValue.IsString: Boolean;
  833. begin
  834. Result := fDataType in [dtString,dtAnsiString,dtWideString];
  835. end;
  836. function TFlexValue.IsVariant: Boolean;
  837. begin
  838. Result := fDataType = dtVariant;
  839. end;
  840. {$IFDEF MSWINDOWS}
  841. procedure TFlexValue.SetAsAnsiString(const Value: AnsiString);
  842. begin
  843. Clear;
  844. fDataIntf := TValueAnsiString.Create(Value);
  845. fDataType := TValueDataType.dtAnsiString;
  846. end;
  847. {$ENDIF}
  848. procedure TFlexValue.SetAsBoolean(const Value: Boolean);
  849. begin
  850. Clear;
  851. fDataIntf := TValueInteger.Create(Value.ToInteger);
  852. fDataType := TValueDataType.dtBoolean;
  853. end;
  854. procedure TFlexValue.SetAsCardinal(const Value: Cardinal);
  855. begin
  856. Clear;
  857. fDataIntf := TValueInteger.Create(Value);
  858. fDataType := TValueDataType.dtInt64;
  859. end;
  860. procedure TFlexValue.SetAsClass(const Value: TClass);
  861. begin
  862. Clear;
  863. fDataIntf := TValuePointer.Create(Value);
  864. fDataType := TValueDataType.dtClass;
  865. end;
  866. {$IFNDEF FPC}
  867. procedure TFlexValue.SetAsCustom(aData: IInterface; aType: TValueDataType);
  868. begin
  869. fDataIntf := aData;
  870. fDataType := aType;
  871. end;
  872. {$ENDIF}
  873. procedure TFlexValue.SetAsDateTime(const Value: TDateTime);
  874. begin
  875. Clear;
  876. fDataIntf := TValueExtended.Create(Value);
  877. fDataType := TValueDataType.dtDateTime;
  878. end;
  879. procedure TFlexValue.SetAsExtended(const Value: Extended);
  880. begin
  881. Clear;
  882. fDataIntf := TValueExtended.Create(Value);
  883. fDataType := TValueDataType.dtExtended;
  884. end;
  885. procedure TFlexValue.SetAsInt64(const Value: Int64);
  886. begin
  887. Clear;
  888. fDataIntf := TValueInteger.Create(Value);
  889. fDataType := TValueDataType.dtInt64;
  890. end;
  891. procedure TFlexValue.SetAsInteger(const Value: Integer);
  892. begin
  893. Clear;
  894. fDataIntf := TValueInteger.Create(Value);
  895. fDataType := TValueDataType.dtInteger;
  896. end;
  897. procedure TFlexValue.SetAsInterface(const Value: IInterface);
  898. begin
  899. {$IFNDEF FPC}
  900. fDataIntf := Value;
  901. {$ELSE}
  902. fDataIntf := Pointer(Value);
  903. {$ENDIF}
  904. fDataType := TValueDataType.dtInterface;
  905. end;
  906. procedure TFlexValue.SetAsObject(const Value: TObject);
  907. begin
  908. Clear;
  909. fDataIntf := TValueObject.Create(Value);
  910. fDataType := TValueDataType.dtObject;
  911. end;
  912. procedure TFlexValue.SetAsPointer(const Value: Pointer);
  913. begin
  914. Clear;
  915. fDataIntf := TValuePointer.Create(Value);
  916. fDataType := TValueDataType.dtPointer;
  917. end;
  918. procedure TFlexValue.SetAsString(const Value: string);
  919. begin
  920. Clear;
  921. fDataIntf := TValueString.Create(Value);
  922. fDataType := TValueDataType.dtString;
  923. end;
  924. function TryVarAsType(aValue : Variant; aVarType : Word) : Boolean;
  925. begin
  926. try
  927. VarAsType(aValue,aVarType);
  928. Result := True;
  929. except
  930. Result := False;
  931. end;
  932. end;
  933. procedure TFlexValue.SetAsVariant(const Value: Variant);
  934. var
  935. i : Int64;
  936. b : Boolean;
  937. f : Extended;
  938. begin
  939. Clear;
  940. case VarType(Value) and varTypeMask of
  941. varEmpty,
  942. varNull : Clear;
  943. varSmallInt,
  944. varInteger,
  945. varByte,
  946. varWord,
  947. varLongWord,
  948. varInt64 : SetAsInt64(Value);
  949. varSingle,
  950. varDouble,
  951. varCurrency : SetAsExtended(Value);
  952. varDate : SetAsDateTime(Value);
  953. varOleStr : SetAsString(Value);
  954. varDispatch : begin
  955. if TryStrToInt64(Value,i) then SetAsInt64(i)
  956. else if TryStrToFloat(Value,f) then SetAsExtended(f)
  957. else if TryStrToBool(Value,b) then SetAsBoolean(b)
  958. else if TryVarAsType(Value,varString) then SetAsString(Value)
  959. else
  960. begin
  961. fDataIntf := TValueVariant.Create(Value);
  962. fDataType := TValueDataType.dtVariant;
  963. end;
  964. end;
  965. //varError : typeString := 'varError';
  966. varBoolean : SetAsBoolean(Value);
  967. //varStrArg : typeString := 'varStrArg';
  968. varString : SetAsString(Value);
  969. //varAny : typeString := 'varAny';
  970. //varTypeMask : typeString := 'varTypeMask';
  971. else
  972. begin
  973. fDataIntf := TValueVariant.Create(Value);
  974. fDataType := TValueDataType.dtVariant;
  975. end;
  976. end;
  977. end;
  978. {$IFDEF MSWINDOWS}
  979. procedure TFlexValue.SetAsWideString(const Value: WideString);
  980. begin
  981. Clear;
  982. fDataIntf := TValueWideString.Create(Value);
  983. fDataType := TValueDataType.dtWideString;
  984. end;
  985. {$ENDIF}
  986. procedure TFlexValue.SetAsVarRec(const Value: TVarRec);
  987. begin
  988. case Value.VType of
  989. {$IFNDEF NEXTGEN}
  990. vtString : AsString := string(Value.VString^);
  991. vtChar : AsString := string(Value.VChar);
  992. {$ENDIF}
  993. {$IFDEF MSWINDOWS}
  994. vtAnsiString : AsAnsiString := AnsiString(Value.VAnsiString);
  995. vtWideString : AsWideString := WideString(Value.VWideString);
  996. {$ENDIF}
  997. {$IFDEF UNICODE}
  998. vtUnicodeString: AsString := string(Value.VUnicodeString);
  999. {$ENDIF UNICODE}
  1000. vtInteger : AsInteger := Value.VInteger;
  1001. vtInt64 : AsInt64 := Value.VInt64^;
  1002. vtExtended : AsExtended := Value.VExtended^;
  1003. vtBoolean : AsBoolean := Value.VBoolean;
  1004. vtVariant : AsVariant := Value.VVariant^;
  1005. vtInterface : AsInterface := IInterface(Value.VInterface);
  1006. vtClass : AsClass := Value.VClass;
  1007. vtObject : AsObject := Value.VObject;
  1008. vtPointer : AsPointer := Value.VPointer;
  1009. else raise Exception.Create('DataType not supported by TFlexValue');
  1010. end;
  1011. {$IFDEF FPC}
  1012. fDataIntf._AddRef;
  1013. {$ENDIF}
  1014. end;
  1015. procedure TFlexValue._AddRef;
  1016. begin
  1017. if Assigned(fDataIntf) then fDataIntf._AddRef;
  1018. end;
  1019. procedure TFlexValue._Release;
  1020. begin
  1021. if Assigned(fDataIntf) then fDataIntf._Release;
  1022. end;
  1023. { TValueStringData }
  1024. constructor TValueString.Create(const Value: string);
  1025. begin
  1026. fData := Value;
  1027. end;
  1028. function TValueString.GetValue: string;
  1029. begin
  1030. Result := fData;
  1031. end;
  1032. procedure TValueString.SetValue(const Value: string);
  1033. begin
  1034. fData := Value;
  1035. end;
  1036. { TValueVariantData }
  1037. constructor TValueVariant.Create(const Value: Variant);
  1038. begin
  1039. fData := Value;
  1040. end;
  1041. function TValueVariant.GetValue: Variant;
  1042. begin
  1043. Result := fData;
  1044. end;
  1045. procedure TValueVariant.SetValue(const Value: Variant);
  1046. begin
  1047. fData := Value;
  1048. end;
  1049. { TValueAnsiStringData }
  1050. {$IFDEF MSWINDOWS}
  1051. constructor TValueAnsiString.Create(const Value: AnsiString);
  1052. begin
  1053. fData := Value;
  1054. end;
  1055. function TValueAnsiString.GetValue: AnsiString;
  1056. begin
  1057. Result := fData;
  1058. end;
  1059. procedure TValueAnsiString.SetValue(const Value: AnsiString);
  1060. begin
  1061. fData := Value;
  1062. end;
  1063. { TValueWideStringData }
  1064. constructor TValueWideString.Create(const Value: WideString);
  1065. begin
  1066. fData := Value;
  1067. end;
  1068. function TValueWideString.GetValue: WideString;
  1069. begin
  1070. Result := fData;
  1071. end;
  1072. procedure TValueWideString.SetValue(const Value: WideString);
  1073. begin
  1074. fData := Value;
  1075. end;
  1076. {$ENDIF}
  1077. { TValueInteger }
  1078. constructor TValueInteger.Create(const Value: Int64);
  1079. begin
  1080. fData := Value;
  1081. end;
  1082. function TValueInteger.GetValue: Int64;
  1083. begin
  1084. Result := fData;
  1085. end;
  1086. procedure TValueInteger.SetValue(const Value: Int64);
  1087. begin
  1088. fData := Value;
  1089. end;
  1090. { TValuePointer }
  1091. constructor TValuePointer.Create(const Value: Pointer);
  1092. begin
  1093. fData := Value;
  1094. end;
  1095. function TValuePointer.GetValue: Pointer;
  1096. begin
  1097. Result := fData;
  1098. end;
  1099. procedure TValuePointer.SetValue(const Value: Pointer);
  1100. begin
  1101. fData := Value;
  1102. end;
  1103. { TValueExtended }
  1104. constructor TValueExtended.Create(const Value: Extended);
  1105. begin
  1106. fData := Value;
  1107. end;
  1108. function TValueExtended.GetValue: Extended;
  1109. begin
  1110. Result := fData;
  1111. end;
  1112. procedure TValueExtended.SetValue(const Value: Extended);
  1113. begin
  1114. fData := Value;
  1115. end;
  1116. { TValueObject }
  1117. constructor TValueObject.Create(const Value: TObject);
  1118. begin
  1119. fData := Value;
  1120. end;
  1121. function TValueObject.GetValue: TObject;
  1122. begin
  1123. Result := fData;
  1124. end;
  1125. procedure TValueObject.SetValue(const Value: TObject);
  1126. begin
  1127. fData := Value;
  1128. end;
  1129. { TFlexPair }
  1130. constructor TFlexPair.Create(const aName: string; aValue: TFlexValue);
  1131. begin
  1132. Name := aName;
  1133. Value := aValue;
  1134. end;
  1135. end.