Ignore unknown properties when reading an object from a stream

We have an application that stores project information in a file in descending order from TPersistent. We use TSteam.ReadComponentRes to read from the 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). This currently causes an exception in the TReader that is created by TStream. We looked at the possibility of creating a streaming descendant of TStream, which uses a Treader descendant, which handles this exception and does not stop reading. Can anyone think of a more elegant way of doing this?

+6
source share
1 answer

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

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

+8
source

Source: https://habr.com/ru/post/889958/


All Articles