Im Artikel <19990420144206.07872.00000...@ngol01.aol.com>, alangll...@aol.com
(AlanGLLoyd) schreibt:
Quote
>Anyone comment on this or why I cannot use TWriter to write all the SG
>properties. Or some code examples please.
TWriter is the low level object, that only does what it's told to do. A
WriteDescendent will tell it to save the published properties only. All other
properties, i.e. all arrays, should be saved by DefineProperties, where you
refer to your code to read and write the additional properties. There you can
refer to your existing code, with the stream creation etc. removed, since the
routine receives the already existing TWriter as an argument. In your example,
this will be the With AWriter Do... block.
BTW, I had problems to save the Objects of a TStringList, since TWriter doesn't
support Nil objects. Of course I had to implement the output of the object data
myself, but couldn't find a solution for simply writing a mark, that no data
exists for a Nil object. You may run into similar problems, when you want to
read back the properties later. Then no indication exists, how many elements
should be read in a Begin/EndList block, and into which array elements the data
should be stored. As a workaround I stored the index of the element prior to
the data, and tested for the existence of such an index value or for an EndList
in the according read loop.
Because of all these problems I'm experimenting with my own I/O now, based on
overloaded prop(var x: y) methods in a new TStreamer object. Then it should be
possible to write a *single* method, that is given a TStreamer object, and
calls it's prop methods for all properties. Depending on the nature of the
TStreamer, a TInStreamer will then copy the data into to fields, or a
TOutStreamer will save the data into the stream.
This method works for all data structures (e.g. records), independently from
any RTTI. It also allows to write *and* later read the data with a single
subroutine, whereas TReader and TWriter require different subroutines, with
duplicate coding efforts and probability of errors. IMO that's important, since
no RTTI will help you in implementing the I/O in DefineProperties :-(
DoDi