Quick.Rtti.fpc.Compatibility.pas 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. { ***************************************************************************
  2. Copyright (c) 2016-2019 Kike Pérez
  3. Unit : Quick.RTTI.fpc.Compatibility (only freepascal)
  4. Description : Delphi compatibility RTTI functions
  5. Author : Kike Pérez
  6. Version : 1.0
  7. Created : 20/08/2018
  8. Modified : 25/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.Rtti.fpc.Compatibility;
  22. {$i QuickLib.inc}
  23. interface
  24. uses
  25. SysUtils,
  26. Rtti;
  27. type
  28. TValueHelper = record helper for TValue
  29. function AsVariant : Variant;
  30. end;
  31. implementation
  32. { TValueHelper }
  33. function TValueHelper.AsVariant: Variant;
  34. begin
  35. case Kind of
  36. tkShortString, tkWideString, tkAnsiString, tkUString : Result := AsString;
  37. tkInteger : result := IntToStr(AsInteger);
  38. tkInt64 : Result := IntToStr(AsInt64);
  39. tkBool : Result := BoolToStr(AsBoolean, True);
  40. tkFloat : Result := FloatToStr(AsExtended);
  41. else
  42. Result := '';
  43. end;
  44. end;
  45. end.