views:

824

answers:

3

Has anyone run into issues serializing components into a file and reading them back, specifically in the area where the component vendor upgrades the VCL components. For example a file serialized with DelphiX and then years later read back with delphiY. Do the serialization formats change and if so what can be done to prevent errors reading in the componets when upgrading.

A: 

Formats will defintely change, as vendors will add features to their components. Serialization simply loops over all published properties and saves them to a stream. When they are read back, each of the properties that is read from the stream will be set back to the component. If the property does not exist anymore, you have a problem. I don't think you can do anything about that besides some basic exception handling.

Best way to guarantee compatibility is to do your own serialization.

birger
A: 

Thanks for the reply. I was trying to avoid custom serialization and take advantage of the each component serialization technique, but with the lack opf any way to "patch" an upgrade to a new component format I guess custom serialization is the only method.

Peter
You can make new releases able to read old streams as long as you still have read support for old and obsolete parameters. The problem lies in getting old releases to read new streams which cannot be done without custom serialization.
Lars Fosdal
+4  A: 

The built-in RTTI based system for serializing published properties is vulnerable to changes in the components. Going forwards is manageable as long as old properties are kept in new objects. I.e. you leave the property interface as is, but can toss away the contents if you like. Going backwards is worse - as a newer version saved property can't be opened in older version load, and that will be a problem.

There are components / libs (http://www.torry.net/quicksearchd.php?String=RTTI&Title=Yes) that can add serialization in XML format and this may help a bit as you can choose to skip content you don't know.

You still need to be mindful about how you design your published content and should probably find a way to "ignore but propagate" content that your current version don't understand. This will allow you to open and change a file in a newer format while attempting to keep newer attributes, instead of stripping them.

Lars Fosdal
Using the VCL-Streaming you can handle missing properties (and missing classes and other errors too) when you use Classes.TReader directly and writing a handler for the OnError event. You found all code needed in the Classes unit.The biggest disadvantage is that your class/classes must derived form TComponent or at least from TPersistent.
Heinz Z.