Bladeren bron

Merge branch 'develop'

Unknown 6 jaren geleden
bovenliggende
commit
8b07cddd01
4 gewijzigde bestanden met toevoegingen van 120 en 9 verwijderingen
  1. 15 1
      Quick.Commons.pas
  2. 29 0
      Quick.Json.fpc.Compatibility.pas
  3. 63 0
      Quick.Rtti.fpc.Compatibility.pas
  4. 13 8
      Quick.Value.pas

+ 15 - 1
Quick.Commons.pas

@@ -7,7 +7,7 @@
   Author      : Kike Pérez
   Version     : 1.8
   Created     : 14/07/2017
-  Modified    : 01/07/2019
+  Modified    : 27/08/2019
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
@@ -279,6 +279,8 @@ type
   function CommaText(aList : TStringList) : string; overload;
   //returns a real comma separated text from array of string
   function CommaText(aArray : TArray<string>) : string; overload;
+  //converts TStrings to array
+  function StringsToArray(aStrings : TStrings) : TArray<string>;
   {$IFDEF MSWINDOWS}
   //process messages on console applications
   procedure ProcessMessages;
@@ -1273,6 +1275,18 @@ begin
   end;
 end;
 
+function StringsToArray(aStrings : TStrings) : TArray<string>;
+var
+  i : Integer;
+begin
+  if aStrings.Count = 0 then Exit;
+  SetLength(Result,aStrings.Count);
+  for i := 0 to aStrings.Count - 1 do
+  begin
+    Result[i] := aStrings[i];
+  end;
+end;
+
 { TCounter }
 
 procedure TCounter.Init(aMaxValue : Integer);

+ 29 - 0
Quick.Json.fpc.Compatibility.pas

@@ -1,3 +1,32 @@
+{ ***************************************************************************
+
+  Copyright (c) 2016-2019 Kike Pérez
+
+  Unit        : Quick.Json.fpc.Compatibility (only freepascal)
+  Description : Delphi Json compatibility functions
+  Author      : Kike Pérez
+  Version     : 1.4
+  Created     : 09/03/2018
+  Modified    : 27/05/2019
+
+  This file is part of QuickLib: https://github.com/exilon/QuickLib
+
+ ***************************************************************************
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+ *************************************************************************** }
+
 unit Quick.Json.fpc.Compatibility;
 
 {$i QuickLib.inc}

+ 63 - 0
Quick.Rtti.fpc.Compatibility.pas

@@ -0,0 +1,63 @@
+{ ***************************************************************************
+
+  Copyright (c) 2016-2019 Kike Pérez
+
+  Unit        : Quick.RTTI.fpc.Compatibility (only freepascal)
+  Description : Delphi compatibility RTTI functions
+  Author      : Kike Pérez
+  Version     : 1.0
+  Created     : 20/08/2018
+  Modified    : 25/08/2019
+
+  This file is part of QuickLib: https://github.com/exilon/QuickLib
+
+ ***************************************************************************
+
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+ *************************************************************************** }
+
+unit Quick.Rtti.fpc.Compatibility;
+
+{$i QuickLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  Rtti;
+
+type
+
+TValueHelper = record helper for TValue
+  function AsVariant : Variant;
+end;
+
+implementation
+
+{ TValueHelper }
+
+function TValueHelper.AsVariant: Variant;
+begin
+  case Kind of
+    tkShortString, tkWideString, tkAnsiString, tkUString : Result := AsString;
+    tkInteger : result := IntToStr(AsInteger);
+    tkInt64 : Result := IntToStr(AsInt64);
+    tkBool : Result := BoolToStr(AsBoolean, True);
+    tkFloat : Result := FloatToStr(AsExtended);
+  else
+    Result := '';
+  end;
+end;
+
+end.

+ 13 - 8
Quick.Value.pas

@@ -7,7 +7,7 @@
   Author      : Kike Pérez
   Version     : 1.5
   Created     : 07/01/2019
-  Modified    : 17/08/2019
+  Modified    : 27/08/2019
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
@@ -218,7 +218,9 @@ type
     function CastToInterface: IInterface;
     function CastToVariant: Variant;
     function CastToCardinal : Cardinal;
+    function CastToVarRec: TVarRec;
     procedure SetAsString(const Value : string);
+    procedure SetAsVarRec(const Value: TVarRec);
     {$IFDEF MSWINDOWS}
     procedure SetAsAnsiString(const Value : AnsiString);
     procedure SetAsWideString(const Value : WideString);
@@ -234,8 +236,6 @@ type
     procedure SetAsVariant(const Value: Variant);
     procedure SetAsCardinal(const Value : Cardinal);
     procedure SetAsInterface(const Value: IInterface);
-    function CastToVarRec: TVarRec;
-    procedure SetToVarRec(const Value: TVarRec);
   public
     constructor Create(const Value: TVarRec);
     property DataType : TValueDataType read fDataType;
@@ -255,7 +255,7 @@ type
     property AsVariant : Variant  read CastToVariant write SetAsVariant;
     property AsCardinal : Cardinal read CastToCardinal write SetAsCardinal;
     property AsDateTime : TDateTime read CastToDateTime write SetAsDateTime;
-    property AsVarRec : TVarRec read CastToVarRec write SetToVarRec;
+    property AsVarRec : TVarRec read CastToVarRec write SetAsVarRec;
     //function AsType<T> : T;
     function  IsNullOrEmpty : Boolean; inline;
     function  IsString : Boolean; inline;
@@ -562,6 +562,7 @@ begin
       dtAnsiString : Result := string((fDataIntf as IValueAnsiString).Value);
       dtWideString : Result := (fDataIntf as IValueWideString).Value;
       {$ENDIF}
+      dtString : Result := (fDataIntf as IValueString).Value;
       dtInteger,
       dtInt64 : Result := (fDataIntf as IValueInteger).Value;
       dtVariant : Result := (fDataIntf as IValueVariant).Value;
@@ -578,11 +579,15 @@ begin
     case fDataType of
       dtNull : Result.VPointer := nil;
       dtBoolean : Result.VBoolean := AsBoolean;
-      dtString : Result.VString := Pointer((fDataIntf as IValueString).Value);
       {$IFDEF MSWINDOWS}
       dtAnsiString : Result.VAnsiString := Pointer((fDataIntf as IValueAnsiString).Value);
       dtWideString : Result.VWideString := Pointer((fDataIntf as IValueWideString).Value);
       {$ENDIF}
+      {$IFNDEF NEXTGEN}
+      dtString : Result.VString := Pointer((fDataIntf as IValueString).Value);
+      {$ELSE}
+      dtString : Result.VUnicodeString := Pointer((fDataIntf as IValueString));
+      {$ENDIF}
       dtInteger : Result.VInteger := (fDataIntf as IValueInteger).Value;
       dtInt64 : Result.VInt64 := Pointer((fDataIntf as IValueInteger).Value);
       //dtVariant : Result.VVariant := ^fDataIntf as IValueVariant).Value;
@@ -1064,7 +1069,9 @@ begin
   fDataIntf := TValueWideString.Create(Value);
   fDataType := TValueDataType.dtWideString;
 end;
-procedure TFlexValue.SetToVarRec(const Value: TVarRec);
+{$ENDIF}
+
+procedure TFlexValue.SetAsVarRec(const Value: TVarRec);
 begin
   case Value.VType of
     {$IFNDEF NEXTGEN}
@@ -1094,8 +1101,6 @@ begin
   {$ENDIF}
 end;
 
-{$ENDIF}
-
 procedure TFlexValue._AddRef;
 begin
   if Assigned(fDataIntf) then fDataIntf._AddRef;