[fpc-pascal] ObjectBinaryToText - how to write only selected property?

Mattias Gaertner nc-gaertnma at netcologne.de
Mon May 7 12:38:22 CEST 2012


On Sat, 5 May 2012 18:15:51 +0200
Krzysztof <dibo20 at wp.pl> wrote:

> Hi,
> 
> ObjectBinaryToText method can save object structure to string, but how
> save only some propertys?

ObjectBinaryToText only converts between to formats.
It does not save object structures. That is done by TWriter.
TWriter normally saves only those properties that differ from the
default value.
If you provide an ancestor it will save only those properties that
differ from the ancestor.


> I could use RTTI and TypeInfo, but
> ObjectBinaryToText can parse property hierarchy
> (Propery1.Subproperty1.Color etc). Or how I can save and read object
> from string without object name?
> Example: I am creating simple theme manager which save settings of
> some control (e.g. TEdit) and must read it not paying attention to the
> component name (Edit1, Edit2, Edit3 etc...) Must work like a template.

See TReader.ReadRootComponent.
If you have a component without csDesigning then it will not set the
name.
If you want to use your theme manager with some designer components
(e.g. the components on a Lazarus or MSEGui designer) then you have to
write a driver that returns the right name. 

Mattias



More information about the fpc-pascal mailing list