Skip to content

Instantly share code, notes, and snippets.

@xavierlopezpujol
Last active May 22, 2023 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavierlopezpujol/ba98e67442a702b8d9c6aee89633b894 to your computer and use it in GitHub Desktop.
Save xavierlopezpujol/ba98e67442a702b8d9c6aee89633b894 to your computer and use it in GitHub Desktop.
Record Serialization Unserialization
program SaveLoadRecordJSON;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Syncommons;
type
TCliente = packed record
Nombre : string;
Direccion : string;
Activo : boolean;
ID : integer;
end;
var
Cliente : TCliente;
Json : string;
begin
// serialize
Cliente.Nombre := 'Juan';
Cliente.Direccion := 'Calle A';
Cliente.Activo := true;
Cliente.ID := 100;
assert(RecordSaveJSON(Cliente,TypeInfo(TCliente)) = '{"Nombre":"Juan","Direccion":"Calle A","Activo":true,"ID":100}');
// unserialize
Json := '{"Nombre":"Joan"}';
RecordLoadJSON(Cliente,Json,TypeInfo(TCliente));
assert(Cliente.Nombre = 'Joan');
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment