Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore unknown properties when reading object from stream

We have an application that stores project information in a file by descending from TPersistent. We use TSteam.ReadComponentRes to read from a stream to the object.

We would like to be able to open project files with unknown properties (from newer versions or other development branches of our application). Currently this results in an exception in TReader, which is created by TStream. We've considered making a TStream descendant that uses a TReader descendant that handles this exception instead of stopping reading. Can anybody think of a more elegant way of doing this?

like image 237
boileau Avatar asked Jun 07 '11 13:06

boileau


1 Answers

Call Stream.ReadResHeader, create a TReader instance, set its OnError event and call Reader.ReadRootComponent and free the reader (i.e. mimic the behaviour of TStream.ReadComponentRes).

Inside the OnError event handler you can set handled := true.

like image 185
Uwe Raabe Avatar answered Sep 20 '22 10:09

Uwe Raabe