Quick.Value.pas 36 KB

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