Delphi 组件序列化 [英] Delphi Component Serialization

查看:23
本文介绍了Delphi 组件序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人遇到过将组件序列化到文件中并将它们读回的问题,特别是在组件供应商升级 VCL 组件的领域.例如,一个文件用 DelphiX 序列化,然后几年后用 delphiY 读回.序列化格式是否发生变化,如果发生变化,可以采取哪些措施来防止升级时读取组件时出错.

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.

推荐答案

用于序列化已发布属性的内置 RTTI 系统容易受到组件更改的影响.只要将旧属性保留在新对象中,就可以管理前进.IE.您可以保留属性界面,但如果您愿意,可以丢弃内容.倒退更糟 - 因为新版本保存的属性无法在旧版本加载时打开,这将是一个问题.

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.

有组件/库(http://www.torry.net/quicksearchd.php?String=RTTI&Title=Yes) 可以添加 XML 格式的序列化,这可能会有所帮助,因为您可以选择跳过不知道的内容.

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.

这篇关于Delphi 组件序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆