Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

FPC compatibility #39

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.dcu
*.bak
__history
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SuperObject

This version is compatible with Delphi and FPC complilers. Also it has Windows/Linux compatibility. Tested with FPC Version 3.0.4, 3.1.1 and last 3.3.1.

## What is JSON ?

- JSON (JavaScript Object Notation) is a lightweight data-interchange format.
Expand Down Expand Up @@ -214,3 +216,68 @@ SO('{собственность: bla bla bla}');
// excadecimal
SO('{foo: \xFF}');
```
## Additional examples

Get a Json string:

function TDataModule3.GetSearchLostStatus: string;
var
X: ISuperObject;
begin
X := SO;
with FServiceThread do
begin
X.B['NowSearchForFile'] := NowSearchForFile;
X.S['LastLostFile'] := LastLostFile;
X.B['NowSearchForRec'] := NowSearchForRec;
X.S['LostRecProgress'] := LostRecProgress;
end;
Result := X.AsJSON;
end;

Get data back from the Json string:

procedure TForm2.SetSearchLostStatus(const Params: string);
var
s: string;
X: ISuperObject;
begin
X := TSuperObject.ParseString(PChar(Params), True);
FNowSearchForFile := not X.B['NowSearchForFile'];
FLastLostFile := X.S['LastLostFile'];
FNowSearchForRec := X.B['NowSearchForRec'];
FLostRecProgress := X.I['LostRecProgress'];
end;

An array usage:

procedure TForm4.SetQueueStatus(const Params: string);
var
j: integer;
X: ISuperObject;
X1: TSuperArray;
s: string;
begin
X := TSuperObject.ParseString(PChar(s), True);
X1 := X.A['Queues'];
StringGrid1.RowCount := X1.Length + 1;
for j := 0 to X1.Length - 1 do
with StringGrid1, X1[j] do
begin
Cells[0, j + 1] := S['NAME'];
if j = 0 then
Cells[1, j + 1] := S['FILES_QUEUED1'] + ' + ' + S['FILES_QUEUED2']
else
Cells[1, j + 1] := S['FILES_QUEUED'];
Cells[2, j + 1] := S['STATUS'];
Cells[3, j + 1] := S['FILES_DONE'];
Cells[4, j + 1] := S['FILES_SKIPPED'];
end;
end;

Path usage:

var s: string; json, field: iSuperObject;
....
field := json.O['Document.CurrentItems.DocumentItem.Fields.FieldValue[1].Value'];
s := json.O['Value'].AsString;
26 changes: 13 additions & 13 deletions superdate.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@
interface

uses
supertypes, supertimezone;
supertimezone;

function JavaToDelphiDateTime(const dt: Int64; const TimeZone: SOString = ''): TDateTime;
function DelphiToJavaDateTime(const dt: TDateTime; const TimeZone: SOString = ''): Int64;
function JavaDateTimeToISO8601Date(const dt: Int64; const TimeZone: SOString = ''): SOString;
function DelphiDateTimeToISO8601Date(const dt: TDateTime; const TimeZone: SOString = ''): SOString;
function ISO8601DateToJavaDateTime(const str: SOString; var ms: Int64; const TimeZone: SOString = ''): Boolean;
function ISO8601DateToDelphiDateTime(const str: SOString; var dt: TDateTime; const TimeZone: SOString = ''): Boolean;
function JavaToDelphiDateTime(const dt: Int64; const TimeZone: string = ''): TDateTime;
function DelphiToJavaDateTime(const dt: TDateTime; const TimeZone: string = ''): Int64;
function JavaDateTimeToISO8601Date(const dt: Int64; const TimeZone: string = ''): string;
function DelphiDateTimeToISO8601Date(const dt: TDateTime; const TimeZone: string = ''): string;
function ISO8601DateToJavaDateTime(const str: string; out ms: Int64; const TimeZone: string = ''): Boolean;
function ISO8601DateToDelphiDateTime(const str: string; out dt: TDateTime; const TimeZone: string = ''): Boolean;

implementation

function JavaToDelphiDateTime(const dt: Int64; const TimeZone: SOString = ''): TDateTime;
function JavaToDelphiDateTime(const dt: Int64; const TimeZone: string = ''): TDateTime;
begin
Result := TSuperTimeZone.Zone[TimeZone].JavaToDelphi(dt);
end;

function DelphiToJavaDateTime(const dt: TDateTime; const TimeZone: SOString = ''): Int64;
function DelphiToJavaDateTime(const dt: TDateTime; const TimeZone: string = ''): Int64;
begin
Result := TSuperTimeZone.Zone[TimeZone].DelphiToJava(dt);
end;

function JavaDateTimeToISO8601Date(const dt: Int64; const TimeZone: SOString = ''): SOString;
function JavaDateTimeToISO8601Date(const dt: Int64; const TimeZone: string = ''): string;
begin
Result := TSuperTimeZone.Zone[TimeZone].JavaToISO8601(dt);
end;

function DelphiDateTimeToISO8601Date(const dt: TDateTime; const TimeZone: SOString = ''): SOString;
function DelphiDateTimeToISO8601Date(const dt: TDateTime; const TimeZone: string = ''): string;
begin
Result := TSuperTimeZone.Zone[TimeZone].DelphiToISO8601(dt);
end;

function ISO8601DateToJavaDateTime(const str: SOString; var ms: Int64; const TimeZone: SOString = ''): Boolean;
function ISO8601DateToJavaDateTime(const str: string; out ms: Int64; const TimeZone: string = ''): Boolean;
begin
Result := TSuperTimeZone.Zone[TimeZone].ISO8601ToJava(str, ms);
end;

function ISO8601DateToDelphiDateTime(const str: SOString; var dt: TDateTime; const TimeZone: SOString = ''): Boolean;
function ISO8601DateToDelphiDateTime(const str: string; out dt: TDateTime; const TimeZone: string): Boolean;
begin
Result := TSuperTimeZone.Zone[TimeZone].ISO8601ToDelphi(str, dt);
end;
Expand Down
Loading