Skip to content

Commit

Permalink
Adding param to manage when it has just one field
Browse files Browse the repository at this point in the history
Adding param to manage the serialization to JSON when the DataSet has just one field
  • Loading branch information
Igor bastos committed Oct 19, 2021
1 parent 9a0696b commit f9ee9ab
Show file tree
Hide file tree
Showing 35 changed files with 32 additions and 205 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
# Delphi history and backups
__history/
__recovery/
Android/
*.~*

# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
Expand Down
58 changes: 0 additions & 58 deletions samples/delphi/mobile/D11/Android/Debug/AndroidManifest.xml

This file was deleted.

4 changes: 0 additions & 4 deletions samples/delphi/mobile/D11/Android/Debug/colors.xml

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions samples/delphi/mobile/D11/Android/Debug/splash_image_def.xml

This file was deleted.

3 changes: 0 additions & 3 deletions samples/delphi/mobile/D11/Android/Debug/strings.xml

This file was deleted.

6 changes: 0 additions & 6 deletions samples/delphi/mobile/D11/Android/Debug/styles-v21.xml

This file was deleted.

6 changes: 0 additions & 6 deletions samples/delphi/mobile/D11/Android/Debug/styles.xml

This file was deleted.

27 changes: 12 additions & 15 deletions samples/delphi/mobile/D11/mobileD11.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,6 @@
</Excluded_Packages>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="Win32\Debug\mobileD11.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>mobileD11.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_SplashImage_640x480.png" Configuration="Debug" Class="Android_SplashImage640">
<Platform Name="Android">
<RemoteName>splash_image.png</RemoteName>
Expand Down Expand Up @@ -385,19 +379,19 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_SplashImage_470x320.png" Configuration="Debug" Class="Android_SplashImage470">
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_NotificationIcon_72x72.png" Configuration="Debug" Class="Android_NotificationIcon72">
<Platform Name="Android">
<RemoteName>splash_image.png</RemoteName>
<RemoteName>ic_notification.png</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_NotificationIcon_36x36.png" Configuration="Debug" Class="Android_NotificationIcon36">
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_SplashImage_470x320.png" Configuration="Debug" Class="Android_SplashImage470">
<Platform Name="Android">
<RemoteName>ic_notification.png</RemoteName>
<RemoteName>splash_image.png</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_NotificationIcon_72x72.png" Configuration="Debug" Class="Android_NotificationIcon72">
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_NotificationIcon_36x36.png" Configuration="Debug" Class="Android_NotificationIcon36">
<Platform Name="Android">
<RemoteName>ic_notification.png</RemoteName>
<Overwrite>true</Overwrite>
Expand Down Expand Up @@ -426,6 +420,12 @@
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\mobileD11.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>mobileD11.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\bin\Artwork\Android\FM_LauncherIcon_96x96.png" Configuration="Debug" Class="Android_LauncherIcon96">
<Platform Name="Android">
<RemoteName>ic_launcher.png</RemoteName>
Expand Down Expand Up @@ -1266,10 +1266,10 @@
</DeployClass>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="OSX64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSXARM64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
Expand All @@ -1279,10 +1279,7 @@
<Platforms>
<Platform value="Android">True</Platform>
<Platform value="Android64">True</Platform>
<Platform value="iOSDevice32">False</Platform>
<Platform value="iOSDevice64">True</Platform>
<Platform value="iOSSimulator">False</Platform>
<Platform value="OSX32">False</Platform>
<Platform value="OSX64">False</Platform>
<Platform value="OSXARM64">False</Platform>
<Platform value="Win32">False</Platform>
Expand Down
29 changes: 19 additions & 10 deletions src/DataSet.Serialize.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ TDataSetSerializeHelper = class Helper for TDataSet
/// <param name="AChildRecords">
/// Exports only childs records from child datasets.
/// </param>
/// <param name="AValueRecords">
/// Inform if it's to export only field values (when there is only 1 field in the DataSet)
/// </param>
/// <returns>
/// Returns a JSON string containing the record data.
/// </returns>
/// <remarks>
/// Invisible fields will not be generated.
/// </remarks>
function ToJSONObjectString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True): string;
function ToJSONObjectString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True; AValueRecords: Boolean = True): string;
/// <summary>
/// Creates an array of JSON objects with all DataSet records.
/// </summary>
Expand All @@ -46,13 +49,16 @@ TDataSetSerializeHelper = class Helper for TDataSet
/// <param name="AChildRecords">
/// Exports only childs records from child datasets.
/// </param>
/// <param name="AValueRecords">
/// Inform if it's to export only field values (when there is only 1 field in the DataSet)
/// </param>
/// <returns>
/// Returns a JSON string with all records from the DataSet.
/// </returns>
/// <remarks>
/// Invisible fields will not be generated.
/// </remarks>
function ToJSONArrayString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True): string;
function ToJSONArrayString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True; AValueRecords: Boolean = True): string;
/// <summary>
/// Creates a JSON object with the data from the current record of DataSet.
/// </summary>
Expand All @@ -62,13 +68,16 @@ TDataSetSerializeHelper = class Helper for TDataSet
/// <param name="AChildRecords">
/// Exports only childs records from child datasets.
/// </param>
/// <param name="AValueRecords">
/// Inform if it's to export only field values (when there is only 1 field in the DataSet)
/// </param>
/// <returns>
/// Returns a JSON object containing the record data.
/// </returns>
/// <remarks>
/// Invisible fields will not be generated.
/// </remarks>
function ToJSONObject(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True): TJSONObject;
function ToJSONObject(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True; AValueRecords: Boolean = True): TJSONObject;
/// <summary>
/// Creates an array of JSON objects with all DataSet records.
/// </summary>
Expand Down Expand Up @@ -232,35 +241,35 @@ function TDataSetSerializeHelper.ToJSONArray(const AOnlyUpdatedRecords: Boolean
end;
end;

function TDataSetSerializeHelper.ToJSONObject(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True): TJSONObject;
function TDataSetSerializeHelper.ToJSONObject(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True; AValueRecords: Boolean = True): TJSONObject;
var
LDataSetSerialize: TDataSetSerialize;
begin
LDataSetSerialize := TDataSetSerialize.Create(Self, AOnlyUpdatedRecords, AChildRecords);
LDataSetSerialize := TDataSetSerialize.Create(Self, AOnlyUpdatedRecords, AChildRecords, AValueRecords);
try
Result := LDataSetSerialize.ToJSONObject;
finally
LDataSetSerialize.Free;
end;
end;

function TDataSetSerializeHelper.ToJSONObjectString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True): string;
function TDataSetSerializeHelper.ToJSONObjectString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True; AValueRecords: Boolean = True): string;
var
LJSONObject: TJSONObject;
begin
LJSONObject := Self.ToJSONObject(AOnlyUpdatedRecords, AChildRecords);
LJSONObject := Self.ToJSONObject(AOnlyUpdatedRecords, AChildRecords, AValueRecords);
try
Result := {$IF DEFINED(FPC)}LJSONObject.AsJSON{$ELSE}LJSONObject.ToString{$ENDIF};
finally
LJSONObject.Free;
end;
end;

function TDataSetSerializeHelper.ToJSONArrayString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True): string;
function TDataSetSerializeHelper.ToJSONArrayString(const AOnlyUpdatedRecords: Boolean = False; const AChildRecords: Boolean = True; AValueRecords: Boolean = True): string;
var
LJSONArray: TJSONArray;
begin
LJSONArray := Self.ToJSONArray(AOnlyUpdatedRecords, AChildRecords);
LJSONArray := Self.ToJSONArray(AOnlyUpdatedRecords, AChildRecords, AValueRecords);
try
Result := {$IF DEFINED(FPC)}LJSONArray.AsJSON{$ELSE}LJSONArray.ToString{$ENDIF};
finally
Expand Down Expand Up @@ -368,4 +377,4 @@ procedure TDataSetSerializeHelper.MergeFromJSONObject(const AJSONString: string)
MergeFromJSONObject({$IF DEFINED(FPC)}GetJSON(AJSONString){$ELSE}TJSONObject.ParseJSONValue(TEncoding.UTF8.GetBytes(AJSONString), 0){$ENDIF} as TJSONObject)
end;

end.
end.

0 comments on commit f9ee9ab

Please sign in to comment.