Quick.Value.pas 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. { ***************************************************************************
  2. Copyright (c) 2016-2019 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 : 27/08/2019
  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. property DataType : TValueDataType read fDataType;
  208. property AsString : string read CastToString write SetAsString;
  209. {$IFDEF MSWINDOWS}
  210. property AsAnsiString : AnsiString read CastToAnsiString write SetAsAnsiString;
  211. property AsWideString : WideString read CastToWideString write SetAsWideString;
  212. {$ENDIF}
  213. property AsInteger : Integer read CastToInteger write SetAsInteger;
  214. property AsInt64 : Int64 read CastToInt64 write SetAsInt64;
  215. property AsExtended : Extended read CastToExtended write SetAsExtended;
  216. property AsBoolean : Boolean read CastToBoolean write SetAsBoolean;
  217. property AsPointer : Pointer read CastToPointer write SetAsPointer;
  218. property AsClass : TClass read CastToClass write SetAsClass;
  219. property AsInterface : IInterface read CastToInterface write SetAsInterface;
  220. property AsObject : TObject read CastToObject write SetAsObject;
  221. property AsVariant : Variant read CastToVariant write SetAsVariant;
  222. property AsCardinal : Cardinal read CastToCardinal write SetAsCardinal;
  223. property AsDateTime : TDateTime read CastToDateTime write SetAsDateTime;
  224. property AsVarRec : TVarRec read CastToVarRec write SetAsVarRec;
  225. //function AsType<T> : T;
  226. function IsNullOrEmpty : Boolean; inline;
  227. function IsString : Boolean; inline;
  228. function IsInteger : Boolean; inline;
  229. function IsFloating : Boolean; inline;
  230. function IsDateTime : Boolean; inline;
  231. function IsBoolean : Boolean; inline;
  232. function IsInterface : Boolean; inline;
  233. function IsObject : Boolean; inline;
  234. function IsPointer : Boolean; inline;
  235. function IsVariant : Boolean; inline;
  236. function IsRealInteger : Boolean;
  237. function IsRealExtended : Boolean;
  238. procedure Clear; inline;
  239. procedure _AddRef; inline;
  240. procedure _Release; inline;
  241. class operator Implicit(const Value : TFlexValue) : string;
  242. class operator Implicit(Value : TFlexValue) : Integer;
  243. class operator Implicit(Value : TFlexValue) : Int64;
  244. class operator Implicit(Value : TFlexValue) : Extended;
  245. class operator Implicit(Value : TFlexValue) : TDateTime;
  246. class operator Implicit(Value : TFlexValue) : Boolean;
  247. class operator Implicit(Value : TFlexValue) : TClass;
  248. class operator Implicit(Value : TFlexValue) : TObject;
  249. class operator Implicit(Value : TFlexValue) : Pointer;
  250. class operator Implicit(Value : TFlexValue) : Variant;
  251. class operator Implicit(Value : TFlexValue) : TVarRec;
  252. class operator Implicit(const Value : string) : TFlexValue;
  253. class operator Implicit(Value : Integer) : TFlexValue;
  254. class operator Implicit(Value : Int64) : TFlexValue;
  255. class operator Implicit(Value : Extended) : TFlexValue;
  256. class operator Implicit(Value : TDateTime) : TFlexValue;
  257. class operator Implicit(Value : Boolean) : TFlexValue;
  258. class operator Implicit(Value : TClass) : TFlexValue;
  259. class operator Implicit(Value : TObject) : TFlexValue;
  260. class operator Implicit(Value : Pointer) : TFlexValue;
  261. class operator Implicit(Value : Variant) : TFlexValue;
  262. class operator Implicit(Value : TVarRec) : TFlexValue;
  263. class operator Equal(a : TFlexValue; b : string) : Boolean;
  264. class operator Equal(a : TFlexValue; b : Integer) : Boolean;
  265. class operator Equal(a : TFlexValue; b : Int64) : Boolean;
  266. class operator Equal(a : TFlexValue; b : Extended) : Boolean;
  267. class operator Equal(a : TFlexValue; b : Boolean) : Boolean;
  268. class operator NotEqual(a : TFlexValue; b : string) : Boolean;
  269. class operator NotEqual(a : TFlexValue; b : Integer) : Boolean;
  270. class operator NotEqual(a : TFlexValue; b : Int64) : Boolean;
  271. class operator NotEqual(a : TFlexValue; b : Extended) : Boolean;
  272. class operator NotEqual(a : TFlexValue; b : Boolean) : Boolean;
  273. class operator GreaterThan(a : TFlexValue; b : Integer) : Boolean;
  274. class operator GreaterThan(a : TFlexValue; b : Int64) : Boolean;
  275. class operator GreaterThan(a : TFlexValue; b : Extended) : Boolean;
  276. class operator GreaterThanOrEqual(a : TFlexValue; b : Integer) : Boolean;
  277. class operator GreaterThanOrEqual(a : TFlexValue; b : Int64) : Boolean;
  278. class operator GreaterThanOrEqual(a : TFlexValue; b : Extended) : Boolean;
  279. class operator LessThan(a : TFlexValue; b : Integer) : Boolean;
  280. class operator LessThan(a : TFlexValue; b : Int64) : Boolean;
  281. class operator LessThan(a : TFlexValue; b : Extended) : Boolean;
  282. class operator LessThanOrEqual(a : TFlexValue; b : Integer) : Boolean;
  283. class operator LessThanOrEqual(a : TFlexValue; b : Int64) : Boolean;
  284. class operator LessThanOrEqual(a : TFlexValue; b : Extended) : Boolean;
  285. end;
  286. PFlexValue = ^TFlexValue;
  287. TFlexPair = record
  288. Name : string;
  289. Value : TFlexValue;
  290. constructor Create(const aName : string; aValue : TFlexValue);
  291. end;
  292. implementation
  293. function TFlexValue.CastToString: string;
  294. begin
  295. try
  296. case fDataType of
  297. dtNull : Result := '';
  298. dtString : Result := (fDataIntf as IValueString).Value;
  299. {$IFDEF MSWINDOWS}
  300. dtAnsiString : Result := string((fDataIntf as IValueAnsiString).Value);
  301. dtWideString : Result := (fDataIntf as IValueWideString).Value;
  302. {$ENDIF}
  303. dtInteger,
  304. dtInt64 : Result := IntToStr(AsInt64);
  305. dtBoolean : Result := BoolToStr(AsBoolean,True);
  306. dtDouble,
  307. dtExtended : Result := FloatToStr(AsExtended);
  308. dtDateTime : Result := DateTimeToStr(AsExtended);
  309. dtVariant : Result := string(AsVariant);
  310. dtClass : Result := AsClass.ClassName;
  311. else raise Exception.Create('DataType not supported');
  312. end;
  313. except
  314. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to String error: %s',[e.message]);
  315. end;
  316. end;
  317. {$IFDEF MSWINDOWS}
  318. function TFlexValue.CastToAnsiString: AnsiString;
  319. begin
  320. try
  321. case fDataType of
  322. dtNull : Result := '';
  323. dtString : Result := AnsiString((fDataIntf as IValueString).Value);
  324. dtAnsiString : Result := (fDataIntf as IValueAnsiString).Value;
  325. dtWideString : Result := AnsiString((fDataIntf as IValueWideString).Value);
  326. dtInteger,
  327. dtInt64 : Result := AnsiString(IntToStr(AsInt64));
  328. dtBoolean : Result := AnsiString(BoolToStr(AsBoolean,True));
  329. dtDouble,
  330. dtExtended : Result := AnsiString(FloatToStr(AsExtended));
  331. dtDateTime : Result := AnsiString(DateTimeToStr(AsExtended));
  332. dtVariant : Result := AnsiString(AsVariant);
  333. else raise Exception.Create('DataType not supported');
  334. end;
  335. except
  336. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to AnsiString error: %s',[e.message]);
  337. end;
  338. end;
  339. function TFlexValue.CastToWideString: WideString;
  340. begin
  341. try
  342. case fDataType of
  343. dtNull : Result := '';
  344. dtString : Result := Widestring((fDataIntf as IValueString).Value);
  345. {$IFDEF MSWINDOWS}
  346. dtAnsiString : Result := Widestring((fDataIntf as IValueAnsiString).Value);
  347. dtWideString : Result := (fDataIntf as IValueWideString).Value;
  348. {$ENDIF}
  349. dtInteger,
  350. dtInt64 : Result := Widestring(IntToStr(AsInt64));
  351. dtBoolean : Result := Widestring(BoolToStr(AsBoolean,True));
  352. dtDouble,
  353. dtExtended : Result := Widestring(FloatToStr(AsExtended));
  354. dtDateTime : Result := Widestring(DateTimeToStr(AsExtended));
  355. dtVariant : Result := Widestring(AsVariant);
  356. else raise Exception.Create('DataType not supported');
  357. end;
  358. except
  359. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to WideString error: %s',[e.message]);
  360. end;
  361. end;
  362. {$ENDIF}
  363. function TFlexValue.CastToBoolean: Boolean;
  364. begin
  365. try
  366. case fDataType of
  367. dtNull : Result := False;
  368. dtString : Result := StrToBool((fDataIntf as IValueString).Value);
  369. {$IFDEF MSWINDOWS}
  370. dtAnsiString : Result := StrToBool(string((fDataIntf as IValueAnsiString).Value));
  371. dtWideString : Result := StrToBool((fDataIntf as IValueWideString).Value);
  372. {$ENDIF}
  373. dtInteger,
  374. dtInt64 :
  375. begin
  376. if (fDataIntf as IValueInteger).Value = 1 then Result := True
  377. else if (fDataIntf as IValueInteger).Value = 0 then Result := False
  378. else raise Exception.Create('Integer value not in 0-1 range');
  379. end;
  380. dtBoolean : Result := Boolean((fDataIntf as IValueInteger).Value);
  381. dtVariant : Result := Boolean(AsVariant);
  382. else raise Exception.Create('DataType not supported');
  383. end;
  384. except
  385. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Boolean error: %s',[e.message]);
  386. end;
  387. end;
  388. function TFlexValue.CastToCardinal: Cardinal;
  389. begin
  390. Result := AsInt64;
  391. end;
  392. function TFlexValue.CastToClass: TClass;
  393. begin
  394. try
  395. case fDataType of
  396. dtNull : Result := nil;
  397. dtClass : Result := (fDataIntf as TValuePointer).Value;
  398. else raise Exception.Create('DataType not supported');
  399. end;
  400. except
  401. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to TClass error: %s',[e.message]);
  402. end;
  403. end;
  404. function TFlexValue.CastToDateTime: TDateTime;
  405. begin
  406. try
  407. case fDataType of
  408. dtNull : Result := 0.0;
  409. dtString : Result := StrToDateTime((fDataIntf as IValueString).Value);
  410. {$IFDEF MSWINDOWS}
  411. dtAnsiString : Result := StrToDateTime(string((fDataIntf as IValueAnsiString).Value));
  412. dtWideString : Result := StrToDateTime((fDataIntf as IValueWideString).Value);
  413. {$ENDIF}
  414. dtInteger,
  415. dtInt64 : Result := FileDateToDateTime(AsInt64);
  416. dtDouble,
  417. dtExtended,
  418. dtDateTime : Result := (fDataIntf as IValueExtended).Value;
  419. dtVariant : Result := Extended(AsVariant);
  420. else raise Exception.Create('DataType not supported');
  421. end;
  422. except
  423. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Extended error: %s',[e.message]);
  424. end;
  425. end;
  426. function TFlexValue.CastToExtended: Extended;
  427. begin
  428. try
  429. case fDataType of
  430. dtNull : Result := 0.0;
  431. dtString : Result := StrToFloat((fDataIntf as IValueString).Value);
  432. {$IFDEF MSWINDOWS}
  433. dtAnsiString : Result := StrToFloat(string((fDataIntf as IValueAnsiString).Value));
  434. dtWideString : Result := StrToFloat((fDataIntf as IValueWideString).Value);
  435. {$ENDIF}
  436. dtInteger,
  437. dtInt64 : Result := AsInt64;
  438. dtBoolean : Result := AsInt64;
  439. dtDouble,
  440. dtExtended,
  441. dtDateTime : Result := (fDataIntf as IValueExtended).Value;
  442. dtVariant : Result := Extended(AsVariant);
  443. else raise Exception.Create('DataType not supported');
  444. end;
  445. except
  446. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Extended error: %s',[e.message]);
  447. end;
  448. end;
  449. function TFlexValue.CastToInt64: Int64;
  450. begin
  451. try
  452. case fDataType of
  453. dtNull : Result := 0;
  454. dtString : Result := StrToInt((fDataIntf as IValueString).Value);
  455. {$IFDEF MSWINDOWS}
  456. dtAnsiString : Result := StrToInt(string((fDataIntf as IValueAnsiString).Value));
  457. dtWideString : Result := StrToInt((fDataIntf as IValueWideString).Value);
  458. {$ENDIF}
  459. dtInteger,
  460. dtInt64 : Result := (fDataIntf as IValueInteger).Value;
  461. dtBoolean : Result := Integer(AsBoolean);
  462. dtDateTime : Result := DateTimeToFileDate((fDataIntf as IValueExtended).Value);
  463. dtVariant : Result := Integer(AsVariant);
  464. else raise Exception.Create('DataType not supported');
  465. end;
  466. except
  467. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Integer error: %s',[e.message]);
  468. end;
  469. end;
  470. function TFlexValue.CastToInteger: Integer;
  471. begin
  472. Result := AsInt64;
  473. end;
  474. function TFlexValue.CastToObject: TObject;
  475. begin
  476. try
  477. case fDataType of
  478. dtObject,
  479. dtOwnedObject : Result := (fDataIntf as IValueObject).Value;
  480. {$IFNDEF FPC}
  481. dtPointer : Result := TObject((fDataIntf as IValueObject).Value);
  482. {$ELSE}
  483. dtPointer : Result := TObject((fDataIntf as IValuePointer).Value);
  484. {$ENDIF}
  485. dtNull : Result := nil;
  486. else raise Exception.Create('DataType not supported');
  487. end;
  488. except
  489. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Object error: %s',[e.message]);
  490. end;
  491. end;
  492. function TFlexValue.CastToPointer: Pointer;
  493. begin
  494. try
  495. case fDataType of
  496. dtObject,
  497. dtOwnedObject : Result := Pointer((fDataIntf as IValueObject).Value);
  498. dtPointer : Result := (fDataIntf as IValuePointer).Value;
  499. dtNull : Result := nil;
  500. else raise Exception.Create('DataType not supported');
  501. end;
  502. except
  503. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Pointer error: %s',[e.message]);
  504. end;
  505. end;
  506. function TFlexValue.CastToVariant: Variant;
  507. begin
  508. try
  509. case fDataType of
  510. dtNull : Result := Variants.Null;
  511. dtBoolean : Result := AsVariant;
  512. {$IFDEF MSWINDOWS}
  513. dtAnsiString : Result := string((fDataIntf as IValueAnsiString).Value);
  514. dtWideString : Result := (fDataIntf as IValueWideString).Value;
  515. {$ENDIF}
  516. dtString : Result := (fDataIntf as IValueString).Value;
  517. dtInteger,
  518. dtInt64 : Result := (fDataIntf as IValueInteger).Value;
  519. dtVariant : Result := (fDataIntf as IValueVariant).Value;
  520. else raise Exception.Create('DataType not supported');
  521. end;
  522. except
  523. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Variant error: %s',[e.message]);
  524. end;
  525. end;
  526. function TFlexValue.CastToVarRec: TVarRec;
  527. begin
  528. try
  529. case fDataType of
  530. dtNull : Result.VPointer := nil;
  531. dtBoolean : Result.VBoolean := AsBoolean;
  532. {$IFDEF MSWINDOWS}
  533. dtAnsiString : Result.VAnsiString := Pointer((fDataIntf as IValueAnsiString).Value);
  534. dtWideString : Result.VWideString := Pointer((fDataIntf as IValueWideString).Value);
  535. {$ENDIF}
  536. {$IFNDEF NEXTGEN}
  537. dtString : Result.VString := Pointer((fDataIntf as IValueString).Value);
  538. {$ELSE}
  539. dtString : Result.VUnicodeString := Pointer((fDataIntf as IValueString));
  540. {$ENDIF}
  541. dtInteger : Result.VInteger := (fDataIntf as IValueInteger).Value;
  542. dtInt64 : Result.VInt64 := Pointer((fDataIntf as IValueInteger).Value);
  543. //dtVariant : Result.VVariant := ^fDataIntf as IValueVariant).Value;
  544. dtObject : Result.VObject := AsObject;
  545. dtPointer : Result.VPointer := AsPointer;
  546. else raise Exception.Create('DataType not supported');
  547. end;
  548. except
  549. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to TVarRec error: %s',[e.message]);
  550. end;
  551. end;
  552. function TFlexValue.CastToInterface: IInterface;
  553. begin
  554. try
  555. case fDataType of
  556. dtNull : Result := nil;
  557. dtInterface : Result := fDataIntf;
  558. dtPointer : Result := IInterface(fDataIntf);
  559. else raise Exception.Create('DataType not supported');
  560. end;
  561. except
  562. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Interface error: %s',[e.message]);
  563. end;
  564. end;
  565. procedure TFlexValue.Clear;
  566. begin
  567. if Pointer(fDataIntf) <> nil then fDataIntf := nil;
  568. fDataType := dtNull;
  569. end;
  570. constructor TFlexValue.Create(const Value: TVarRec);
  571. begin
  572. case Value.VType of
  573. {$IFNDEF NEXTGEN}
  574. vtString : AsString := string(Value.VString^);
  575. vtChar : AsString := string(Value.VChar);
  576. {$ENDIF}
  577. {$IFDEF MSWINDOWS}
  578. vtAnsiString : AsAnsiString := AnsiString(Value.VAnsiString);
  579. vtWideString : AsWideString := WideString(Value.VWideString);
  580. {$ENDIF}
  581. {$IFDEF UNICODE}
  582. vtUnicodeString: AsString := string(Value.VUnicodeString);
  583. {$ENDIF UNICODE}
  584. vtInteger : AsInteger := Value.VInteger;
  585. vtInt64 : AsInt64 := Value.VInt64^;
  586. vtExtended : AsExtended := Value.VExtended^;
  587. vtBoolean : AsBoolean := Value.VBoolean;
  588. vtVariant : AsVariant := Value.VVariant^;
  589. vtInterface : AsInterface := IInterface(Value.VInterface);
  590. vtClass : AsClass := Value.VClass;
  591. vtObject : AsObject := Value.VObject;
  592. vtPointer : AsPointer := Value.VPointer;
  593. else raise Exception.Create('DataType not supported by TFlexValue');
  594. end;
  595. {$IFDEF FPC}
  596. fDataIntf._AddRef;
  597. {$ENDIF}
  598. end;
  599. class operator TFlexValue.Implicit(Value: TFlexValue): Boolean;
  600. begin
  601. Result := Value.AsBoolean;
  602. end;
  603. class operator TFlexValue.Implicit(const Value: TFlexValue): string;
  604. begin
  605. Result := Value.AsString;
  606. end;
  607. class operator TFlexValue.Implicit(Value: TFlexValue): TObject;
  608. begin
  609. Result := Value.AsObject;
  610. end;
  611. class operator TFlexValue.Implicit(Value: TFlexValue): Pointer;
  612. begin
  613. Result := Value.AsPointer;
  614. end;
  615. class operator TFlexValue.Implicit(Value: TFlexValue): TDateTime;
  616. begin
  617. Result := Value.AsDateTime;
  618. end;
  619. class operator TFlexValue.Implicit(Value: TFlexValue): TClass;
  620. begin
  621. Result := Value.AsClass;
  622. end;
  623. class operator TFlexValue.Implicit(Value: TFlexValue): Int64;
  624. begin
  625. Result := Value.AsInt64;
  626. end;
  627. class operator TFlexValue.Implicit(Value: TFlexValue): Integer;
  628. begin
  629. Result := Value.AsInteger;
  630. end;
  631. class operator TFlexValue.Implicit(Value: TFlexValue): Extended;
  632. begin
  633. Result := Value.AsExtended;
  634. end;
  635. class operator TFlexValue.Implicit(Value: TFlexValue): Variant;
  636. begin
  637. Result := Value.AsVariant;
  638. end;
  639. class operator TFlexValue.Implicit(Value: TFlexValue): TVarRec;
  640. begin
  641. Result := Value.AsVarRec;
  642. end;
  643. class operator TFlexValue.Implicit(Value: Variant): TFlexValue;
  644. begin
  645. Result.AsVariant := Value;
  646. end;
  647. class operator TFlexValue.Implicit(const Value : string) : TFlexValue;
  648. begin
  649. Result.AsString := Value;
  650. end;
  651. class operator TFlexValue.Implicit(Value : Integer) : TFlexValue;
  652. begin
  653. Result.AsInteger := Value;
  654. end;
  655. class operator TFlexValue.Implicit(Value : Int64) : TFlexValue;
  656. begin
  657. Result.AsInt64 := Value;
  658. end;
  659. class operator TFlexValue.Implicit(Value : Extended) : TFlexValue;
  660. begin
  661. Result.AsExtended := Value;
  662. end;
  663. class operator TFlexValue.Implicit(Value : TDateTime) : TFlexValue;
  664. begin
  665. Result.AsDateTime := Value;
  666. end;
  667. class operator TFlexValue.Implicit(Value : Boolean) : TFlexValue;
  668. begin
  669. Result.AsBoolean := Value;
  670. end;
  671. class operator TFlexValue.Implicit(Value : TClass) : TFlexValue;
  672. begin
  673. Result.AsClass := Value;
  674. end;
  675. class operator TFlexValue.Implicit(Value : TObject) : TFlexValue;
  676. begin
  677. Result.AsObject := Value;
  678. end;
  679. class operator TFlexValue.Implicit(Value : Pointer) : TFlexValue;
  680. begin
  681. Result.AsPointer := Value;
  682. end;
  683. class operator TFlexValue.Implicit(Value: TVarRec): TFlexValue;
  684. begin
  685. Result.AsVarRec := Value;
  686. end;
  687. class operator TFlexValue.Equal(a: TFlexValue; b: string): Boolean;
  688. begin
  689. Result := a.AsString = b;
  690. end;
  691. class operator TFlexValue.Equal(a: TFlexValue; b: Int64): Boolean;
  692. begin
  693. Result := a.AsInt64 = b;
  694. end;
  695. class operator TFlexValue.Equal(a: TFlexValue; b: Extended): Boolean;
  696. begin
  697. Result := a.AsExtended = b;
  698. end;
  699. class operator TFlexValue.Equal(a: TFlexValue; b: Boolean): Boolean;
  700. begin
  701. Result := a.AsBoolean = b;
  702. end;
  703. class operator TFlexValue.Equal(a : TFlexValue; b : Integer) : Boolean;
  704. begin
  705. Result := a.AsInteger = b;
  706. end;
  707. class operator TFlexValue.NotEqual(a: TFlexValue; b: Int64): Boolean;
  708. begin
  709. Result := a.AsInt64 <> b;
  710. end;
  711. class operator TFlexValue.NotEqual(a: TFlexValue; b: Integer): Boolean;
  712. begin
  713. Result := a.AsInteger <> b;
  714. end;
  715. class operator TFlexValue.NotEqual(a: TFlexValue; b: string): Boolean;
  716. begin
  717. Result := a.AsString <> b;
  718. end;
  719. class operator TFlexValue.NotEqual(a: TFlexValue; b: Boolean): Boolean;
  720. begin
  721. Result := a.AsBoolean <> b;
  722. end;
  723. class operator TFlexValue.NotEqual(a: TFlexValue; b: Extended): Boolean;
  724. begin
  725. Result := a.AsExtended <> b;
  726. end;
  727. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Integer): Boolean;
  728. begin
  729. Result := a.AsInteger > b;
  730. end;
  731. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Int64): Boolean;
  732. begin
  733. Result := a.AsInt64 > b;
  734. end;
  735. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Extended): Boolean;
  736. begin
  737. Result := a.AsExtended > b;
  738. end;
  739. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Integer): Boolean;
  740. begin
  741. Result := a.AsInteger >= b;
  742. end;
  743. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Int64): Boolean;
  744. begin
  745. Result := a.AsInt64 >= b;
  746. end;
  747. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Extended): Boolean;
  748. begin
  749. Result := a.AsExtended >= b;
  750. end;
  751. class operator TFlexValue.LessThan(a: TFlexValue; b: Integer): Boolean;
  752. begin
  753. Result := a.AsInteger < b;
  754. end;
  755. class operator TFlexValue.LessThan(a: TFlexValue; b: Int64): Boolean;
  756. begin
  757. Result := a.AsInt64 < b;
  758. end;
  759. class operator TFlexValue.LessThan(a: TFlexValue; b: Extended): Boolean;
  760. begin
  761. Result := a.AsExtended < b;
  762. end;
  763. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b : Integer): Boolean;
  764. begin
  765. Result := a.AsInteger <= b;
  766. end;
  767. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b : Int64): Boolean;
  768. begin
  769. Result := a.AsInt64 <= b;
  770. end;
  771. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b: Extended): Boolean;
  772. begin
  773. Result := a.AsExtended <= b;
  774. end;
  775. function TFlexValue.IsBoolean: Boolean;
  776. begin
  777. Result := fDataType = dtBoolean;
  778. end;
  779. function TFlexValue.IsDateTime: Boolean;
  780. begin
  781. Result := fDataType = dtDateTime;
  782. end;
  783. function TFlexValue.IsFloating: Boolean;
  784. begin
  785. Result := fDataType in [dtDouble,dtExtended];
  786. end;
  787. function TFlexValue.IsInteger: Boolean;
  788. begin
  789. Result := fDataType in [dtInteger,dtInt64];
  790. end;
  791. function TFlexValue.IsInterface: Boolean;
  792. begin
  793. Result := fDataType = dtInterface;
  794. end;
  795. function TFlexValue.IsNullOrEmpty: Boolean;
  796. begin
  797. Result := fDataIntf = nil;
  798. end;
  799. function TFlexValue.IsObject: Boolean;
  800. begin
  801. Result := fDataType = dtObject;
  802. end;
  803. function TFlexValue.IsPointer: Boolean;
  804. begin
  805. Result := fDataType = dtPointer;
  806. end;
  807. function TFlexValue.IsRealExtended: Boolean;
  808. var
  809. i : Extended;
  810. begin
  811. Result := TryStrToFloat(AsString,i);
  812. end;
  813. function TFlexValue.IsRealInteger: Boolean;
  814. var
  815. i : Int64;
  816. begin
  817. Result := TryStrToInt64(AsString,i);
  818. end;
  819. function TFlexValue.IsString: Boolean;
  820. begin
  821. Result := fDataType in [dtString,dtAnsiString,dtWideString];
  822. end;
  823. function TFlexValue.IsVariant: Boolean;
  824. begin
  825. Result := fDataType = dtVariant;
  826. end;
  827. {$IFDEF MSWINDOWS}
  828. procedure TFlexValue.SetAsAnsiString(const Value: AnsiString);
  829. begin
  830. Clear;
  831. fDataIntf := TValueAnsiString.Create(Value);
  832. fDataType := TValueDataType.dtAnsiString;
  833. end;
  834. {$ENDIF}
  835. procedure TFlexValue.SetAsBoolean(const Value: Boolean);
  836. begin
  837. Clear;
  838. fDataIntf := TValueInteger.Create(Value.ToInteger);
  839. fDataType := TValueDataType.dtBoolean;
  840. end;
  841. procedure TFlexValue.SetAsCardinal(const Value: Cardinal);
  842. begin
  843. Clear;
  844. fDataIntf := TValueInteger.Create(Value);
  845. fDataType := TValueDataType.dtInt64;
  846. end;
  847. procedure TFlexValue.SetAsClass(const Value: TClass);
  848. begin
  849. Clear;
  850. fDataIntf := TValuePointer.Create(Value);
  851. fDataType := TValueDataType.dtClass;
  852. end;
  853. procedure TFlexValue.SetAsDateTime(const Value: TDateTime);
  854. begin
  855. Clear;
  856. fDataIntf := TValueExtended.Create(Value);
  857. fDataType := TValueDataType.dtDateTime;
  858. end;
  859. procedure TFlexValue.SetAsExtended(const Value: Extended);
  860. begin
  861. Clear;
  862. fDataIntf := TValueExtended.Create(Value);
  863. fDataType := TValueDataType.dtExtended;
  864. end;
  865. procedure TFlexValue.SetAsInt64(const Value: Int64);
  866. begin
  867. Clear;
  868. fDataIntf := TValueInteger.Create(Value);
  869. fDataType := TValueDataType.dtInt64;
  870. end;
  871. procedure TFlexValue.SetAsInteger(const Value: Integer);
  872. begin
  873. Clear;
  874. fDataIntf := TValueInteger.Create(Value);
  875. fDataType := TValueDataType.dtInteger;
  876. end;
  877. procedure TFlexValue.SetAsInterface(const Value: IInterface);
  878. begin
  879. {$IFNDEF FPC}
  880. fDataIntf := Value;
  881. {$ELSE}
  882. fDataIntf := Pointer(Value);
  883. {$ENDIF}
  884. fDataType := TValueDataType.dtInterface;
  885. end;
  886. procedure TFlexValue.SetAsObject(const Value: TObject);
  887. begin
  888. Clear;
  889. fDataIntf := TValueObject.Create(Value);
  890. fDataType := TValueDataType.dtObject;
  891. end;
  892. procedure TFlexValue.SetAsPointer(const Value: Pointer);
  893. begin
  894. Clear;
  895. fDataIntf := TValuePointer.Create(Value);
  896. fDataType := TValueDataType.dtPointer;
  897. end;
  898. procedure TFlexValue.SetAsString(const Value: string);
  899. begin
  900. Clear;
  901. fDataIntf := TValueString.Create(Value);
  902. fDataType := TValueDataType.dtString;
  903. end;
  904. function TryVarAsType(aValue : Variant; aVarType : Word) : Boolean;
  905. begin
  906. try
  907. VarAsType(aValue,aVarType);
  908. Result := True;
  909. except
  910. Result := False;
  911. end;
  912. end;
  913. procedure TFlexValue.SetAsVariant(const Value: Variant);
  914. begin
  915. Clear;
  916. case VarType(Value) and varTypeMask of
  917. varEmpty,
  918. varNull : Clear;
  919. varSmallInt,
  920. varInteger,
  921. varByte,
  922. varWord,
  923. varLongWord,
  924. varInt64 : SetAsInt64(Value);
  925. varSingle,
  926. varDouble,
  927. varCurrency : SetAsExtended(Value);
  928. varDate : SetAsDateTime(Value);
  929. varOleStr : SetAsString(Value);
  930. varDispatch : begin
  931. if TryVarAsType(Value,varInt64) then SetAsInt64(Value)
  932. else if TryVarAsType(Value,varDouble) then SetAsExtended(Value)
  933. else if TryVarAsType(Value,varBoolean) then SetAsBoolean(Value)
  934. else if TryVarAsType(Value,varString) then SetAsString(Value)
  935. else
  936. begin
  937. fDataIntf := TValueVariant.Create(Value);
  938. fDataType := TValueDataType.dtVariant;
  939. end;
  940. end;
  941. //varError : typeString := 'varError';
  942. varBoolean : SetAsBoolean(Value);
  943. //varStrArg : typeString := 'varStrArg';
  944. varString : SetAsString(Value);
  945. //varAny : typeString := 'varAny';
  946. //varTypeMask : typeString := 'varTypeMask';
  947. else
  948. begin
  949. fDataIntf := TValueVariant.Create(Value);
  950. fDataType := TValueDataType.dtVariant;
  951. end;
  952. end;
  953. end;
  954. {$IFDEF MSWINDOWS}
  955. procedure TFlexValue.SetAsWideString(const Value: WideString);
  956. begin
  957. Clear;
  958. fDataIntf := TValueWideString.Create(Value);
  959. fDataType := TValueDataType.dtWideString;
  960. end;
  961. {$ENDIF}
  962. procedure TFlexValue.SetAsVarRec(const Value: TVarRec);
  963. begin
  964. case Value.VType of
  965. {$IFNDEF NEXTGEN}
  966. vtString : AsString := string(Value.VString^);
  967. vtChar : AsString := string(Value.VChar);
  968. {$ENDIF}
  969. {$IFDEF MSWINDOWS}
  970. vtAnsiString : AsAnsiString := AnsiString(Value.VAnsiString);
  971. vtWideString : AsWideString := WideString(Value.VWideString);
  972. {$ENDIF}
  973. {$IFDEF UNICODE}
  974. vtUnicodeString: AsString := string(Value.VUnicodeString);
  975. {$ENDIF UNICODE}
  976. vtInteger : AsInteger := Value.VInteger;
  977. vtInt64 : AsInt64 := Value.VInt64^;
  978. vtExtended : AsExtended := Value.VExtended^;
  979. vtBoolean : AsBoolean := Value.VBoolean;
  980. vtVariant : AsVariant := Value.VVariant^;
  981. vtInterface : AsInterface := IInterface(Value.VInterface);
  982. vtClass : AsClass := Value.VClass;
  983. vtObject : AsObject := Value.VObject;
  984. vtPointer : AsPointer := Value.VPointer;
  985. else raise Exception.Create('DataType not supported by TFlexValue');
  986. end;
  987. {$IFDEF FPC}
  988. fDataIntf._AddRef;
  989. {$ENDIF}
  990. end;
  991. procedure TFlexValue._AddRef;
  992. begin
  993. if Assigned(fDataIntf) then fDataIntf._AddRef;
  994. end;
  995. procedure TFlexValue._Release;
  996. begin
  997. if Assigned(fDataIntf) then fDataIntf._Release;
  998. end;
  999. { TValueStringData }
  1000. constructor TValueString.Create(const Value: string);
  1001. begin
  1002. fData := Value;
  1003. end;
  1004. function TValueString.GetValue: string;
  1005. begin
  1006. Result := fData;
  1007. end;
  1008. procedure TValueString.SetValue(const Value: string);
  1009. begin
  1010. fData := Value;
  1011. end;
  1012. { TValueVariantData }
  1013. constructor TValueVariant.Create(const Value: Variant);
  1014. begin
  1015. fData := Value;
  1016. end;
  1017. function TValueVariant.GetValue: Variant;
  1018. begin
  1019. Result := fData;
  1020. end;
  1021. procedure TValueVariant.SetValue(const Value: Variant);
  1022. begin
  1023. fData := Value;
  1024. end;
  1025. { TValueAnsiStringData }
  1026. {$IFDEF MSWINDOWS}
  1027. constructor TValueAnsiString.Create(const Value: AnsiString);
  1028. begin
  1029. fData := Value;
  1030. end;
  1031. function TValueAnsiString.GetValue: AnsiString;
  1032. begin
  1033. Result := fData;
  1034. end;
  1035. procedure TValueAnsiString.SetValue(const Value: AnsiString);
  1036. begin
  1037. fData := Value;
  1038. end;
  1039. { TValueWideStringData }
  1040. constructor TValueWideString.Create(const Value: WideString);
  1041. begin
  1042. fData := Value;
  1043. end;
  1044. function TValueWideString.GetValue: WideString;
  1045. begin
  1046. Result := fData;
  1047. end;
  1048. procedure TValueWideString.SetValue(const Value: WideString);
  1049. begin
  1050. fData := Value;
  1051. end;
  1052. {$ENDIF}
  1053. { TValueInteger }
  1054. constructor TValueInteger.Create(const Value: Int64);
  1055. begin
  1056. fData := Value;
  1057. end;
  1058. function TValueInteger.GetValue: Int64;
  1059. begin
  1060. Result := fData;
  1061. end;
  1062. procedure TValueInteger.SetValue(const Value: Int64);
  1063. begin
  1064. fData := Value;
  1065. end;
  1066. { TValuePointer }
  1067. constructor TValuePointer.Create(const Value: Pointer);
  1068. begin
  1069. fData := Value;
  1070. end;
  1071. function TValuePointer.GetValue: Pointer;
  1072. begin
  1073. Result := fData;
  1074. end;
  1075. procedure TValuePointer.SetValue(const Value: Pointer);
  1076. begin
  1077. fData := Value;
  1078. end;
  1079. { TValueExtended }
  1080. constructor TValueExtended.Create(const Value: Extended);
  1081. begin
  1082. fData := Value;
  1083. end;
  1084. function TValueExtended.GetValue: Extended;
  1085. begin
  1086. Result := fData;
  1087. end;
  1088. procedure TValueExtended.SetValue(const Value: Extended);
  1089. begin
  1090. fData := Value;
  1091. end;
  1092. { TValueObject }
  1093. constructor TValueObject.Create(const Value: TObject);
  1094. begin
  1095. fData := Value;
  1096. end;
  1097. function TValueObject.GetValue: TObject;
  1098. begin
  1099. Result := fData;
  1100. end;
  1101. procedure TValueObject.SetValue(const Value: TObject);
  1102. begin
  1103. fData := Value;
  1104. end;
  1105. { TFlexPair }
  1106. constructor TFlexPair.Create(const aName: string; aValue: TFlexValue);
  1107. begin
  1108. Name := aName;
  1109. Value := aValue;
  1110. end;
  1111. end.