Summary

BeginObject method is a low-level method, which allows to de-serialize object like data manually. Every call to BeginObject method should be matched by a call to NG.Serialization.TDeserializer.EndObject method.

Syntax

procedure BeginObject; overload;

Remarks

To read general discussion of when and how to use BeginObject method, read the description of another BeginObject overload. This overload is a simplified version of another one, and differs from it only in the absence of AType output parameter. This overload can be used when working with polymorphic object values is not required. There are two major cases:

  • First, when de-serialization of values of Delphi record types are performed; since record does not support inheritance, there no need to save it run-time type.
  • Second, when run-time type of the object values does not change over time and always remains the same. Despite the fact, that Delphi objects support inheritance, its not usually used for serialization related tasks; thus in such cases there no need to save object run-time type.

Examples

DelphiCopyCode imageCopy Code
D.BeginObject; // We know, here should be a book, and nothing else.
book := TBook.Create;

while D.HasNext do
begin
  if D.Prop = 'Tittle' then
    book.Tittle := D.Value<string>
  else if D.Prop = 'Author' then
    book.Author := D.Value<string>
  else
    raise Exception.Create('Unexpected property name');
end;

S.EndObject;