Skip to content

Commit 57b9737

Browse files
committed
[compatibility] fixes for older delphi versions
1 parent 6cd3daf commit 57b9737

File tree

4 files changed

+91
-8
lines changed

4 files changed

+91
-8
lines changed

Quick.Chrono.pas

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131

3232
interface
3333

34-
{$HPPEMIT LEGACYHPP}
34+
{$IFDEF DELPHIXE7_UP}
35+
{$HPPEMIT LEGACYHPP}
36+
{$ENDIF}
3537

3638
{$i QuickLib.inc}
3739

Quick.FaultControl.pas

+4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ constructor TFaultControl.Create;
106106
fMaxRetries := 0;
107107
fWaitTimeBetweenRetries := 0;
108108
fWaitTimeMultiplierFactor := 1;
109+
{$IFDEF DELPHIXE7_UP}
109110
fWaitTimeArray := [];
111+
{$ELSE}
112+
fWaitTimeArray := nil;
113+
{$ENDIF}
110114
end;
111115

112116
function TFaultControl.NeedToRetry: Boolean;

Quick.HttpClient.pas

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ constructor THttpRequestResponse.Create(aResponse : TIdHTTPResponse; const aCont
381381
if fResponse = nil then
382382
begin
383383
fResponse := TJSONObject.Create;
384-
{$IFDEF DELPHIXE7_UP}
384+
{$IFDEF DELPHIXE4_UP}
385385
fResponse.AddPair('Result',aContent);
386386
{$ELSE}
387387
fResponse.Add('Result',aContent);

Quick.Json.Serializer.pas

+83-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Author : Kike Pérez
88
Version : 1.11
99
Created : 21/05/2018
10-
Modified : 07/04/2020
10+
Modified : 27/04/2020
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -49,12 +49,15 @@ interface
4949
{$ELSE}
5050
{$IFDEF DELPHIXE7_UP}
5151
System.Json,
52+
{$ELSE}
53+
Data.DBXJSON,
5254
{$ENDIF}
5355
{$IFDEF DELPHIRX10_UP}
5456

5557
{$ENDIF}
5658
Variants,
5759
{$ENDIF}
60+
Generics.Collections,
5861
Quick.RTTI.Utils,
5962
DateUtils,
6063
Quick.Commons,
@@ -83,6 +86,30 @@ TCustomNameProperty = class(TCustomAttribute)
8386
constructor Create(const aName: string);
8487
property Name : string read fName;
8588
end;
89+
{$IFNDEF DELPHIXE7_UP}
90+
TJSONArrayHelper = class helper for Data.DBXJson.TJSONArray
91+
private
92+
function GetItem(aValue : Integer) : TJSONValue;
93+
public
94+
function Count : Integer;
95+
property Items[index : Integer] : TJSONValue read GetItem;
96+
procedure SetElements(aElements : TList<TJSONValue>);
97+
end;
98+
99+
TJSONValueHelper = class helper for Data.DBXJson.TJSONValue
100+
public
101+
function ToJson : string;
102+
end;
103+
104+
TJSONObjectHelper = class helper for Data.DBXJson.TJSONObject
105+
private
106+
function GetPair(aValue : Integer) : TJSONPair;
107+
public
108+
function Count : Integer;
109+
function GetValue(const aName : string) : TJSONValue;
110+
property Pairs[index : Integer] : TJSONPair read GetPair;
111+
end;
112+
{$ENDIF}
86113
{$ENDIF}
87114

88115
IJsonSerializer = interface
@@ -190,9 +217,6 @@ EJsonSerializerError = class(Exception);
190217

191218
implementation
192219

193-
uses
194-
Generics.Collections;
195-
196220
{ TRTTIJson }
197221

198222
{$IFNDEF FPC}
@@ -394,7 +418,7 @@ function TRTTIJson.DeserializeRecord(const aRecord : TValue; aObject : TObject;
394418
{$IFDEF DELPHIRX10_UP}
395419
rValue := DeserializeType(aObject,rField.FieldType.TypeKind,rField.FieldType.Handle,TJsonValue(member).value)
396420
{$ELSE}
397-
rValue := DeserializeType(aObject,rField.FieldType.TypeKind,rField.FieldType.Handle,member.JsonString.ToString)
421+
rValue := DeserializeType(aObject,rField.FieldType.TypeKind,rField.FieldType.Handle,member.Value)
398422
{$ENDIF}
399423
else rValue := DeserializeType(aObject,rField.FieldType.TypeKind,rField.FieldType.Handle,member.ToJSON);
400424
end;
@@ -677,7 +701,7 @@ function TRTTIJson.DeserializeProperty(aObject : TObject; const aName : string;
677701
{$IFDEF DELPHIRX10_UP}
678702
rValue := DeserializeType(aObject,aProperty.PropertyType.TypeKind,aProperty.GetValue(aObject).TypeInfo,TJsonValue(member).value)
679703
{$ELSE}
680-
rValue := DeserializeType(aObject,aProperty.PropertyType.TypeKind,aProperty.GetValue(aObject).TypeInfo,member.JsonString.ToString)
704+
rValue := DeserializeType(aObject,aProperty.PropertyType.TypeKind,aProperty.GetValue(aObject).TypeInfo,member.Value)
681705
{$ENDIF}
682706
else rValue := DeserializeType(aObject,aProperty.PropertyType.TypeKind,aProperty.GetValue(aObject).TypeInfo,member.ToJSON);
683707
{$ELSE}
@@ -1702,6 +1726,59 @@ constructor TCustomNameProperty.Create(const aName: string);
17021726
end;
17031727
{$ENDIF}
17041728

1729+
{$IF NOT DEFINED(DELPHIXE7_UP) AND NOT DEFINED(FPC)}
1730+
{ TJSONArrayHelper }
1731+
1732+
function TJSONArrayHelper.Count: Integer;
1733+
begin
1734+
Result := Self.Size;
1735+
end;
1736+
1737+
function TJSONArrayHelper.GetItem(aValue: Integer): TJSONValue;
1738+
begin
1739+
Result := Self.Get(aValue);
1740+
end;
1741+
1742+
procedure TJSONArrayHelper.SetElements(aElements: TList<TJSONValue>);
1743+
var
1744+
jvalue : TJSONValue;
1745+
begin
1746+
for jvalue in aElements do Self.AddElement(jvalue);
1747+
aElements.Free;
1748+
end;
1749+
1750+
{ TJSONValueHelper }
1751+
1752+
function TJSONValueHelper.ToJson: string;
1753+
begin
1754+
Result := Self.ToString;
1755+
end;
1756+
1757+
1758+
{ TJSONObjectHelper }
1759+
1760+
function TJSONObjectHelper.Count: Integer;
1761+
begin
1762+
Result := Self.Size;
1763+
end;
1764+
1765+
function TJSONObjectHelper.GetValue(const aName: string): TJSONValue;
1766+
var
1767+
jPair : TJSONPair;
1768+
begin
1769+
Result := nil;
1770+
for jPair in Self do
1771+
begin
1772+
if jPair.JsonString.ToString = aName then Exit(jPair.JsonValue);
1773+
end;
1774+
end;
1775+
1776+
function TJSONObjectHelper.GetPair(aValue: Integer) : TJSONPair;
1777+
begin
1778+
Result := Self.Get(aValue);
1779+
end;
1780+
1781+
{$ENDIF}
17051782

17061783
end.
17071784

0 commit comments

Comments
 (0)