Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-05

ObjectBinaryToText - how to write only selected property?

7 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Krzysztof

Hi,

ObjectBinaryToText method can save object structure to string, but how save only some propertys? 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.

Regards

Reply by email

Martin Schreiber
to Krzysztof
Krzysztof wrote 11 lines
Hi, ObjectBinaryToText method can save object structure to string, but how save only some propertys? 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.

tskinmanager of MSEgui does something similar, see lib/common/kernel/mseskin.pas.
Every MSEgui component has the procedure updateskin() which normally will be called after loading the form. tmsecomponent.updateskin() calls the global oninitskinobject handler which is assigned to the active <tskincontroller> which updates the default values of the component according to the skin settings. Values which are already set by the form resources normally are not changed so it is possible to define component specific exceptions to the current theme, for instance a specific color, frame or font.

objectbinarytotext() converts from binary streamed data written by twriter to a human readable text representation, it does not scan the properties, twriter.writeproperties() does this. The whole Delphi/FPC component streaming system is very locked because of the many private fields and procedures. I think it is difficult to use it as base for your undertaking.

Martin

Reply by email

Mattias Gaertner
to Krzysztof: ObjectBinaryToText method can save object structure to string, but how save only some…
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.

Show quoted text 7 lines
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

Reply by email

Graeme Geldenhuys
to Krzysztof: ObjectBinaryToText method can save object structure to string, but how save only some…
Krzysztof wrote
I could use RTTI and TypeInfo, but ObjectBinaryToText can parse property hierarchy (Propery1.Subproperty1.Color etc).

Out of interest, I have written an "extended" RTTI unit which is used in the tiOPF project. All the functions in that unit support what I call "property paths", which means you can get and set properties like 'myobject.Propery1.Subproperty1.Color' on a object. The unit is called tiRTTI.pas, and tiOPF is hosted on SourceForge. The unit handles nil valued sub-properties correctly as well. The tiRTTI unit has minimal dependency on the other tiOPF units, so it will be very easy to make it a pure stand-alone unit.

http://sourceforge.net/projects/tiopf/

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Krzysztof
to Graeme Geldenhuys

Thanks to all for tips

@Graeme. I tried download tiOPS source but can't extract archive on linux. I never had problems with compressed files on linux. Which format is this? Can you send mi tiRTTI file via e-mail?

Thanks

2012/5/7 Graeme Geldenhuys :

Show quoted text 30 lines
On 5 May 2012 18:15, Krzysztof wrote: > I could use RTTI and TypeInfo, but > ObjectBinaryToText can parse property hierarchy > (Propery1.Subproperty1.Color etc). Out of interest, I have written an "extended" RTTI unit which is used in the tiOPF project. All the functions in that unit support what I call "property paths", which means you can get and set properties like 'myobject.Propery1.Subproperty1.Color' on a object. The unit is called tiRTTI.pas, and tiOPF is hosted on SourceForge. The unit handles nil valued sub-properties correctly as well. The tiRTTI unit has minimal dependency on the other tiOPF units, so it will be very easy to make it a pure stand-alone unit.  http://sourceforge.net/projects/tiopf/ -- Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Graeme Geldenhuys
to Krzysztof

Hi,

@Graeme. I tried download tiOPS source but can't extract archive on linux. I never had problems with compressed files on linux. Which format is this?

I meant you should be able to simply check-out the tiRTTI.pas unit form the SubVersion source code repository, or browse the repository with your web browser and save the unit to file. I'm not sure what archive you are referring to.

Can you send mi tiRTTI file via e-mail?

Done.

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net

Reply by email

Krzysztof
to Graeme Geldenhuys

Thanks! I will look at this

2012/5/8 Graeme Geldenhuys :

Show quoted text 30 lines
Hi, > @Graeme. I tried download tiOPS source but can't extract archive on > linux. I never had problems with compressed files on linux. Which > format is this? I meant you should be able to simply check-out the tiRTTI.pas unit form the SubVersion source code repository, or browse the repository with your web browser and save the unit to file. I'm not sure what archive you are referring to. > Can you send mi tiRTTI file via e-mail? Done. -- Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://fpgui.sourceforge.net _______________________________________________ fpc-pascal maillist  -   http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email