Monday 17th July.
Graeme Keast gave a presentation on his code to write objects to JSON, and how he uses RTTI to achieve this.
He created code that allowed him to write objects to JSON and restore them from JSON. The classes didn’t have to belong to any particular hierarchy; they didn’t have to descend from TPersistent. Attributes were used to indicate which properties were to be persisted.
He showed how he used RTTI to access the attributes at run-time and then access property values.
His technique also allowed him to persist and restore the data in a dataset, so he could save data from an SQL dataset to JSON, and restore the data to a ClientDataset.
He then discussed some of the challenges of restoring objects from JSON, including the variety of constructor signatures, and resolving references to existing objects.
He also showed how he used a Parnassus FireMonkey container to embed a FireMonkey 3D viewer into a VCL form.
Then John McDonald gave a short presentation on Streams.
A file can be considered as a stream of bytes that you read or write.
There are other situations where you get streams of bytes, and using Delphi TStream and related classes, you can handle all these streams in the same way.
John showed examples of file streams, resource streams, memory streams and string streams. He mentioned other streams including database blobs, and the inputs and outputs of encryption and compression libraries.
He then showed how the TStreamReader and TStreamWriter classes can be used to read and write character text. These classes do the encoding and decoding for UTF-8, ASCII and other character encodings. The TBinaryReader and TBinaryWriter classes can be used to read and write binary data.
He discussed various traps:
The run-time performance of the standard TStreamReader is very poor.
Seek and Size are not implemented on all Streams.
soBeginning, soCurrent and soEnd should be used with a Seek call, not soFromBeginning, etc.
When using a StreamReader, call StreamReader.DiscardBufferedData after calling Seek.
When using a StreamWriter, call StreamWriter.Flush before calling Seek.
The meeting was held at the Melbourne Men’s Shed,
situated in the Federation Square Car Park building, off Russell St Extension.