Objects (Deserialization)

<< Click to Display Table of Contents >>

Navigation:  Export >

Objects (Deserialization)

Query can be used for unmarshalling (deserialization) of objects. Use Unserialize method and pass reference to function which creates and return object instance

Example:

 

JSON:

{"CustomerId": 1,"Active": true,"Name": "Jason Orr","Address": "Ap #387-8229 Nullam Road","City": "Kilsyth","Country": "HN","Email": "lacus.Nulla@Classaptenttaciti.ca" },
{"CustomerId": 2,"Active": true,"Name": "Devin Herman","Address": "P.O. Box 905, 9608 Etiam St.","City": "Portici","Country": "HR","Email": "Integer.vulputate.risus@est.co.uk" },

 

Class declaration:

 

  TCustomer = class
  public
    CustomerID: integer;
    Active: boolean;
    Name, Address, City, Country, Email: string;
  end;
 
  TCustList = TObjectList<TCustomer>;

 

Code:

 

  var CL: TCustList;
  begin
    CL := TCustList.Create;
    THtSQL.FromFolder(SelectedFolder, 'select * from customers', []).Unserialize(
      function: TObject begin 
       Result := TCustomer.Create; 
       CL.Add(TCustomer(Result));
      end);