Quick.Value.pas 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  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. dtVariant : Result := IInterface(fDataIntf);
  569. else raise Exception.Create('DataType not supported');
  570. end;
  571. except
  572. on E : Exception do raise Exception.CreateFmt('TFlexValue conversion to Interface error: %s',[e.message]);
  573. end;
  574. end;
  575. procedure TFlexValue.Clear;
  576. begin
  577. if Pointer(fDataIntf) <> nil then fDataIntf := nil;
  578. fDataType := dtNull;
  579. end;
  580. constructor TFlexValue.Create(const Value: TVarRec);
  581. begin
  582. case Value.VType of
  583. {$IFNDEF NEXTGEN}
  584. vtString : AsString := string(Value.VString^);
  585. vtChar : AsString := string(Value.VChar);
  586. {$ENDIF}
  587. {$IFDEF MSWINDOWS}
  588. vtAnsiString : AsAnsiString := AnsiString(Value.VAnsiString);
  589. vtWideString : AsWideString := WideString(Value.VWideString);
  590. {$ENDIF}
  591. {$IFDEF UNICODE}
  592. vtUnicodeString: AsString := string(Value.VUnicodeString);
  593. {$ENDIF UNICODE}
  594. vtInteger : AsInteger := Value.VInteger;
  595. vtInt64 : AsInt64 := Value.VInt64^;
  596. vtExtended : AsExtended := Value.VExtended^;
  597. vtBoolean : AsBoolean := Value.VBoolean;
  598. vtVariant : AsVariant := Value.VVariant^;
  599. vtInterface : AsInterface := IInterface(Value.VInterface);
  600. vtClass : AsClass := Value.VClass;
  601. vtObject : AsObject := Value.VObject;
  602. vtPointer : AsPointer := Value.VPointer;
  603. else raise Exception.Create('DataType not supported by TFlexValue');
  604. end;
  605. {$IFDEF FPC}
  606. fDataIntf._AddRef;
  607. {$ENDIF}
  608. end;
  609. class operator TFlexValue.Implicit(Value: TFlexValue): Boolean;
  610. begin
  611. Result := Value.AsBoolean;
  612. end;
  613. class operator TFlexValue.Implicit(const Value: TFlexValue): string;
  614. begin
  615. Result := Value.AsString;
  616. end;
  617. class operator TFlexValue.Implicit(Value: TFlexValue): TObject;
  618. begin
  619. Result := Value.AsObject;
  620. end;
  621. class operator TFlexValue.Implicit(Value: TFlexValue): Pointer;
  622. begin
  623. Result := Value.AsPointer;
  624. end;
  625. class operator TFlexValue.Implicit(Value: TFlexValue): TDateTime;
  626. begin
  627. Result := Value.AsDateTime;
  628. end;
  629. class operator TFlexValue.Implicit(Value: TFlexValue): TClass;
  630. begin
  631. Result := Value.AsClass;
  632. end;
  633. class operator TFlexValue.Implicit(Value: TFlexValue): Int64;
  634. begin
  635. Result := Value.AsInt64;
  636. end;
  637. class operator TFlexValue.Implicit(Value: TFlexValue): Integer;
  638. begin
  639. Result := Value.AsInteger;
  640. end;
  641. class operator TFlexValue.Implicit(Value: TFlexValue): Extended;
  642. begin
  643. Result := Value.AsExtended;
  644. end;
  645. class operator TFlexValue.Implicit(Value: TFlexValue): Variant;
  646. begin
  647. Result := Value.AsVariant;
  648. end;
  649. class operator TFlexValue.Implicit(Value: TFlexValue): TVarRec;
  650. begin
  651. Result := Value.AsVarRec;
  652. end;
  653. class operator TFlexValue.Implicit(Value: Variant): TFlexValue;
  654. begin
  655. Result.AsVariant := Value;
  656. end;
  657. class operator TFlexValue.Implicit(const Value : string) : TFlexValue;
  658. begin
  659. Result.AsString := Value;
  660. end;
  661. class operator TFlexValue.Implicit(Value : Integer) : TFlexValue;
  662. begin
  663. Result.AsInteger := Value;
  664. end;
  665. class operator TFlexValue.Implicit(Value : Int64) : TFlexValue;
  666. begin
  667. Result.AsInt64 := Value;
  668. end;
  669. class operator TFlexValue.Implicit(Value : Extended) : TFlexValue;
  670. begin
  671. Result.AsExtended := Value;
  672. end;
  673. class operator TFlexValue.Implicit(Value : TDateTime) : TFlexValue;
  674. begin
  675. Result.AsDateTime := Value;
  676. end;
  677. class operator TFlexValue.Implicit(Value : Boolean) : TFlexValue;
  678. begin
  679. Result.AsBoolean := Value;
  680. end;
  681. class operator TFlexValue.Implicit(Value : TClass) : TFlexValue;
  682. begin
  683. Result.AsClass := Value;
  684. end;
  685. class operator TFlexValue.Implicit(Value : TObject) : TFlexValue;
  686. begin
  687. Result.AsObject := Value;
  688. end;
  689. class operator TFlexValue.Implicit(Value : Pointer) : TFlexValue;
  690. begin
  691. Result.AsPointer := Value;
  692. end;
  693. class operator TFlexValue.Implicit(Value: TVarRec): TFlexValue;
  694. begin
  695. Result.AsVarRec := Value;
  696. end;
  697. class operator TFlexValue.Equal(a: TFlexValue; b: string): Boolean;
  698. begin
  699. Result := a.AsString = b;
  700. end;
  701. class operator TFlexValue.Equal(a: TFlexValue; b: Int64): Boolean;
  702. begin
  703. Result := a.AsInt64 = b;
  704. end;
  705. class operator TFlexValue.Equal(a: TFlexValue; b: Extended): Boolean;
  706. begin
  707. Result := a.AsExtended = b;
  708. end;
  709. class operator TFlexValue.Equal(a: TFlexValue; b: Boolean): Boolean;
  710. begin
  711. Result := a.AsBoolean = b;
  712. end;
  713. class operator TFlexValue.Equal(a : TFlexValue; b : Integer) : Boolean;
  714. begin
  715. Result := a.AsInteger = b;
  716. end;
  717. class operator TFlexValue.NotEqual(a: TFlexValue; b: Int64): Boolean;
  718. begin
  719. Result := a.AsInt64 <> b;
  720. end;
  721. class operator TFlexValue.NotEqual(a: TFlexValue; b: Integer): Boolean;
  722. begin
  723. Result := a.AsInteger <> b;
  724. end;
  725. class operator TFlexValue.NotEqual(a: TFlexValue; b: string): Boolean;
  726. begin
  727. Result := a.AsString <> b;
  728. end;
  729. class operator TFlexValue.NotEqual(a: TFlexValue; b: Boolean): Boolean;
  730. begin
  731. Result := a.AsBoolean <> b;
  732. end;
  733. class operator TFlexValue.NotEqual(a: TFlexValue; b: Extended): Boolean;
  734. begin
  735. Result := a.AsExtended <> b;
  736. end;
  737. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Integer): Boolean;
  738. begin
  739. Result := a.AsInteger > b;
  740. end;
  741. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Int64): Boolean;
  742. begin
  743. Result := a.AsInt64 > b;
  744. end;
  745. class operator TFlexValue.GreaterThan(a: TFlexValue; b: Extended): Boolean;
  746. begin
  747. Result := a.AsExtended > b;
  748. end;
  749. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Integer): Boolean;
  750. begin
  751. Result := a.AsInteger >= b;
  752. end;
  753. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Int64): Boolean;
  754. begin
  755. Result := a.AsInt64 >= b;
  756. end;
  757. class operator TFlexValue.GreaterThanOrEqual(a: TFlexValue; b: Extended): Boolean;
  758. begin
  759. Result := a.AsExtended >= b;
  760. end;
  761. class operator TFlexValue.LessThan(a: TFlexValue; b: Integer): Boolean;
  762. begin
  763. Result := a.AsInteger < b;
  764. end;
  765. class operator TFlexValue.LessThan(a: TFlexValue; b: Int64): Boolean;
  766. begin
  767. Result := a.AsInt64 < b;
  768. end;
  769. class operator TFlexValue.LessThan(a: TFlexValue; b: Extended): Boolean;
  770. begin
  771. Result := a.AsExtended < b;
  772. end;
  773. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b : Integer): Boolean;
  774. begin
  775. Result := a.AsInteger <= b;
  776. end;
  777. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b : Int64): Boolean;
  778. begin
  779. Result := a.AsInt64 <= b;
  780. end;
  781. class operator TFlexValue.LessThanOrEqual(a: TFlexValue; b: Extended): Boolean;
  782. begin
  783. Result := a.AsExtended <= b;
  784. end;
  785. function TFlexValue.IsArray: Boolean;
  786. begin
  787. Result := fDataType = dtArray;
  788. end;
  789. function TFlexValue.IsBoolean: Boolean;
  790. begin
  791. Result := fDataType = dtBoolean;
  792. end;
  793. function TFlexValue.IsDateTime: Boolean;
  794. begin
  795. Result := fDataType = dtDateTime;
  796. end;
  797. function TFlexValue.IsFloating: Boolean;
  798. begin
  799. Result := fDataType in [dtDouble,dtExtended];
  800. end;
  801. function TFlexValue.IsInteger: Boolean;
  802. begin
  803. Result := fDataType in [dtInteger,dtInt64];
  804. end;
  805. function TFlexValue.IsInterface: Boolean;
  806. begin
  807. Result := fDataType = dtInterface;
  808. end;
  809. function TFlexValue.IsNullOrEmpty: Boolean;
  810. begin
  811. Result := fDataIntf = nil;
  812. end;
  813. function TFlexValue.IsObject: Boolean;
  814. begin
  815. Result := fDataType = dtObject;
  816. end;
  817. function TFlexValue.IsPointer: Boolean;
  818. begin
  819. Result := fDataType = dtPointer;
  820. end;
  821. function TFlexValue.IsRealExtended: Boolean;
  822. var
  823. i : Extended;
  824. begin
  825. Result := TryStrToFloat(AsString,i);
  826. end;
  827. function TFlexValue.IsRealInteger: Boolean;
  828. var
  829. i : Int64;
  830. begin
  831. Result := TryStrToInt64(AsString,i);
  832. end;
  833. function TFlexValue.IsString: Boolean;
  834. begin
  835. Result := fDataType in [dtString,dtAnsiString,dtWideString];
  836. end;
  837. function TFlexValue.IsVariant: Boolean;
  838. begin
  839. Result := fDataType = dtVariant;
  840. end;
  841. {$IFDEF MSWINDOWS}
  842. procedure TFlexValue.SetAsAnsiString(const Value: AnsiString);
  843. begin
  844. Clear;
  845. fDataIntf := TValueAnsiString.Create(Value);
  846. fDataType := TValueDataType.dtAnsiString;
  847. end;
  848. {$ENDIF}
  849. procedure TFlexValue.SetAsBoolean(const Value: Boolean);
  850. begin
  851. Clear;
  852. fDataIntf := TValueInteger.Create(Value.ToInteger);
  853. fDataType := TValueDataType.dtBoolean;
  854. end;
  855. procedure TFlexValue.SetAsCardinal(const Value: Cardinal);
  856. begin
  857. Clear;
  858. fDataIntf := TValueInteger.Create(Value);
  859. fDataType := TValueDataType.dtInt64;
  860. end;
  861. procedure TFlexValue.SetAsClass(const Value: TClass);
  862. begin
  863. Clear;
  864. fDataIntf := TValuePointer.Create(Value);
  865. fDataType := TValueDataType.dtClass;
  866. end;
  867. {$IFNDEF FPC}
  868. procedure TFlexValue.SetAsCustom(aData: IInterface; aType: TValueDataType);
  869. begin
  870. fDataIntf := aData;
  871. fDataType := aType;
  872. end;
  873. {$ENDIF}
  874. procedure TFlexValue.SetAsDateTime(const Value: TDateTime);
  875. begin
  876. Clear;
  877. fDataIntf := TValueExtended.Create(Value);
  878. fDataType := TValueDataType.dtDateTime;
  879. end;
  880. procedure TFlexValue.SetAsExtended(const Value: Extended);
  881. begin
  882. Clear;
  883. fDataIntf := TValueExtended.Create(Value);
  884. fDataType := TValueDataType.dtExtended;
  885. end;
  886. procedure TFlexValue.SetAsInt64(const Value: Int64);
  887. begin
  888. Clear;
  889. fDataIntf := TValueInteger.Create(Value);
  890. fDataType := TValueDataType.dtInt64;
  891. end;
  892. procedure TFlexValue.SetAsInteger(const Value: Integer);
  893. begin
  894. Clear;
  895. fDataIntf := TValueInteger.Create(Value);
  896. fDataType := TValueDataType.dtInteger;
  897. end;
  898. procedure TFlexValue.SetAsInterface(const Value: IInterface);
  899. begin
  900. {$IFNDEF FPC}
  901. fDataIntf := Value;
  902. {$ELSE}
  903. fDataIntf := Pointer(Value);
  904. {$ENDIF}
  905. fDataType := TValueDataType.dtInterface;
  906. end;
  907. procedure TFlexValue.SetAsObject(const Value: TObject);
  908. begin
  909. Clear;
  910. fDataIntf := TValueObject.Create(Value);
  911. fDataType := TValueDataType.dtObject;
  912. end;
  913. procedure TFlexValue.SetAsPointer(const Value: Pointer);
  914. begin
  915. Clear;
  916. fDataIntf := TValuePointer.Create(Value);
  917. fDataType := TValueDataType.dtPointer;
  918. end;
  919. procedure TFlexValue.SetAsString(const Value: string);
  920. begin
  921. Clear;
  922. fDataIntf := TValueString.Create(Value);
  923. fDataType := TValueDataType.dtString;
  924. end;
  925. function TryVarAsType(aValue : Variant; aVarType : Word) : Boolean;
  926. begin
  927. try
  928. VarAsType(aValue,aVarType);
  929. Result := True;
  930. except
  931. Result := False;
  932. end;
  933. end;
  934. procedure TFlexValue.SetAsVariant(const Value: Variant);
  935. var
  936. i : Int64;
  937. b : Boolean;
  938. f : Extended;
  939. begin
  940. Clear;
  941. case VarType(Value) and varTypeMask of
  942. varEmpty,
  943. varNull : Clear;
  944. varSmallInt,
  945. varInteger,
  946. varByte,
  947. varWord,
  948. varLongWord,
  949. varInt64 : SetAsInt64(Value);
  950. varSingle,
  951. varDouble,
  952. varCurrency : SetAsExtended(Value);
  953. varDate : SetAsDateTime(Value);
  954. varOleStr : SetAsString(Value);
  955. varDispatch : begin
  956. if TryStrToInt64(Value,i) then SetAsInt64(i)
  957. else if TryStrToFloat(Value,f) then SetAsExtended(f)
  958. else if TryStrToBool(Value,b) then SetAsBoolean(b)
  959. else if TryVarAsType(Value,varString) then SetAsString(Value)
  960. else
  961. begin
  962. fDataIntf := TValueVariant.Create(Value);
  963. fDataType := TValueDataType.dtVariant;
  964. end;
  965. end;
  966. //varError : typeString := 'varError';
  967. varBoolean : SetAsBoolean(Value);
  968. //varStrArg : typeString := 'varStrArg';
  969. varString : SetAsString(Value);
  970. //varAny : typeString := 'varAny';
  971. //varTypeMask : typeString := 'varTypeMask';
  972. else
  973. begin
  974. fDataIntf := TValueVariant.Create(Value);
  975. fDataType := TValueDataType.dtVariant;
  976. end;
  977. end;
  978. end;
  979. {$IFDEF MSWINDOWS}
  980. procedure TFlexValue.SetAsWideString(const Value: WideString);
  981. begin
  982. Clear;
  983. fDataIntf := TValueWideString.Create(Value);
  984. fDataType := TValueDataType.dtWideString;
  985. end;
  986. {$ENDIF}
  987. procedure TFlexValue.SetAsVarRec(const Value: TVarRec);
  988. begin
  989. case Value.VType of
  990. {$IFNDEF NEXTGEN}
  991. vtString : AsString := string(Value.VString^);
  992. vtChar : AsString := string(Value.VChar);
  993. {$ENDIF}
  994. {$IFDEF MSWINDOWS}
  995. vtAnsiString : AsAnsiString := AnsiString(Value.VAnsiString);
  996. vtWideString : AsWideString := WideString(Value.VWideString);
  997. {$ENDIF}
  998. {$IFDEF UNICODE}
  999. vtUnicodeString: AsString := string(Value.VUnicodeString);
  1000. {$ENDIF UNICODE}
  1001. vtInteger : AsInteger := Value.VInteger;
  1002. vtInt64 : AsInt64 := Value.VInt64^;
  1003. vtExtended : AsExtended := Value.VExtended^;
  1004. vtBoolean : AsBoolean := Value.VBoolean;
  1005. vtVariant : AsVariant := Value.VVariant^;
  1006. vtInterface : AsInterface := IInterface(Value.VInterface);
  1007. vtClass : AsClass := Value.VClass;
  1008. vtObject : AsObject := Value.VObject;
  1009. vtPointer : AsPointer := Value.VPointer;
  1010. else raise Exception.Create('DataType not supported by TFlexValue');
  1011. end;
  1012. {$IFDEF FPC}
  1013. fDataIntf._AddRef;
  1014. {$ENDIF}
  1015. end;
  1016. procedure TFlexValue._AddRef;
  1017. begin
  1018. if Assigned(fDataIntf) then fDataIntf._AddRef;
  1019. end;
  1020. procedure TFlexValue._Release;
  1021. begin
  1022. if Assigned(fDataIntf) then fDataIntf._Release;
  1023. end;
  1024. { TValueStringData }
  1025. constructor TValueString.Create(const Value: string);
  1026. begin
  1027. fData := Value;
  1028. end;
  1029. function TValueString.GetValue: string;
  1030. begin
  1031. Result := fData;
  1032. end;
  1033. procedure TValueString.SetValue(const Value: string);
  1034. begin
  1035. fData := Value;
  1036. end;
  1037. { TValueVariantData }
  1038. constructor TValueVariant.Create(const Value: Variant);
  1039. begin
  1040. fData := Value;
  1041. end;
  1042. function TValueVariant.GetValue: Variant;
  1043. begin
  1044. Result := fData;
  1045. end;
  1046. procedure TValueVariant.SetValue(const Value: Variant);
  1047. begin
  1048. fData := Value;
  1049. end;
  1050. { TValueAnsiStringData }
  1051. {$IFDEF MSWINDOWS}
  1052. constructor TValueAnsiString.Create(const Value: AnsiString);
  1053. begin
  1054. fData := Value;
  1055. end;
  1056. function TValueAnsiString.GetValue: AnsiString;
  1057. begin
  1058. Result := fData;
  1059. end;
  1060. procedure TValueAnsiString.SetValue(const Value: AnsiString);
  1061. begin
  1062. fData := Value;
  1063. end;
  1064. { TValueWideStringData }
  1065. constructor TValueWideString.Create(const Value: WideString);
  1066. begin
  1067. fData := Value;
  1068. end;
  1069. function TValueWideString.GetValue: WideString;
  1070. begin
  1071. Result := fData;
  1072. end;
  1073. procedure TValueWideString.SetValue(const Value: WideString);
  1074. begin
  1075. fData := Value;
  1076. end;
  1077. {$ENDIF}
  1078. { TValueInteger }
  1079. constructor TValueInteger.Create(const Value: Int64);
  1080. begin
  1081. fData := Value;
  1082. end;
  1083. function TValueInteger.GetValue: Int64;
  1084. begin
  1085. Result := fData;
  1086. end;
  1087. procedure TValueInteger.SetValue(const Value: Int64);
  1088. begin
  1089. fData := Value;
  1090. end;
  1091. { TValuePointer }
  1092. constructor TValuePointer.Create(const Value: Pointer);
  1093. begin
  1094. fData := Value;
  1095. end;
  1096. function TValuePointer.GetValue: Pointer;
  1097. begin
  1098. Result := fData;
  1099. end;
  1100. procedure TValuePointer.SetValue(const Value: Pointer);
  1101. begin
  1102. fData := Value;
  1103. end;
  1104. { TValueExtended }
  1105. constructor TValueExtended.Create(const Value: Extended);
  1106. begin
  1107. fData := Value;
  1108. end;
  1109. function TValueExtended.GetValue: Extended;
  1110. begin
  1111. Result := fData;
  1112. end;
  1113. procedure TValueExtended.SetValue(const Value: Extended);
  1114. begin
  1115. fData := Value;
  1116. end;
  1117. { TValueObject }
  1118. constructor TValueObject.Create(const Value: TObject);
  1119. begin
  1120. fData := Value;
  1121. end;
  1122. function TValueObject.GetValue: TObject;
  1123. begin
  1124. Result := fData;
  1125. end;
  1126. procedure TValueObject.SetValue(const Value: TObject);
  1127. begin
  1128. fData := Value;
  1129. end;
  1130. { TFlexPair }
  1131. constructor TFlexPair.Create(const aName: string; aValue: TFlexValue);
  1132. begin
  1133. Name := aName;
  1134. Value := aValue;
  1135. end;
  1136. end.