-
Notifications
You must be signed in to change notification settings - Fork 3
Serializable Pascal Records (RecordUtils.pas)
Pascal Records are extremely useful for working with the Parallel Type Library because they are automatically memory managed. However not being classes, they are more difficult to automatically populate from Streamed Data without using published properties.
The RecordUtils.pas file uses RTTI to automatically serialise and deserialse as value pairs. eg
TMyRecordStatus = (mrsNone, mrsBusy, mrsIdle);
TMyRecord=Record
id : integer;
Name: string;
isNew : boolean;
Status : TMyRecordStatus; // enum
end;
WIll be serialised as
id=1
Name=Test1
isNew=True
Status=mrsBusy
Currently only the Data types Integer, String, Boolean and any Enumerated type are supported. NESTED Records is not supported at this time.
Yes, arrays are supported. The Above example as an array would be output as:
id[0]=1
Name[0]=Test1
isNew[0]=True
Status[0]=mrsBusy
id[1]=2
Name[1]=Test2
isNew[1]=false
Status[1]=mrsNone
The Data Type and Array count can optionally be included in the data in the following way:
Single Record
RecordType=TMyRecord
Array of Records
RecordType=TMyRecord[]
RecordCount=2
The alternative format where each id is prefixed with the data type is also supported for Parsing (but will not be output in this format). Eg
Single Record
TMyRecord.id=1
TMyRecord.Name=Test1
TMyRecord.isNew=True
TMyRecord.Status=mrsBusy
Array of Records
TMyRecord[0].id=1
TMyRecord[0].Name=Test1
TMyRecord[0].isNew=True
TMyRecord[0].Status=mrsBusy
TMyRecord[1].id=1
TMyRecord[1].Name=Test1
TMyRecord[1].isNew=True
TMyRecord[1].Status=mrsBusy
Internally the string structure is managed as a TStringlist, so the line ending symantics are a consequence of that architecture. The
The <CR> (Carriage Return, ASCII-13) cannot be represented as a single line in the TStringlist (by default) and consequently are always converted to <LF> (Line Feed, ASCII-10). So <CRLF> becomes <LF>, <CR> becomes <LF>, <CRLF><LF> becomes <LF><LF>. At this stage, to preserve <CR>, you must pre-process the string representation using an alternate encoding scheme (eg HTML encoding )