长寿使用Delphi文本DFM格式为我自己的商店和检索 [英] Longevity of using the Delphi text DFM format for my own store and retrieve

查看:271
本文介绍了长寿使用Delphi文本DFM格式为我自己的商店和检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着时间的推移,我已经滚动了自己的格式来保存和加载对象属性,但是不得不重新访问我想知道如何使用Delphi自己的文本DFM格式。我知道这是一个真正的内部格式,但是读者现在看起来很明确,它可以处理所有类型的财产。有人有任何关于可能的陷阱的意见吗?

Over time I've rolled my own formats for saving and loading object properties but on having to revisit this I'm wondering about using Delphi's own text DFM format. I know tha this is really an 'internal' format, but the reader for it now seems pretty well defined and it copes with all types of property. Has anyone any comments about possible pitfalls?

推荐答案

我不会说DFM是一个内部格式。当然,Delphi在内部使用表单和数据模块,但执行流式传输的TReader和TWriter类可以公开访问,甚至记录在案。所以他们也明确地是为最终用户。

I wouldn't really say that DFM is an 'internal format'. Sure Delphi uses it internally for forms and datamodules, but TReader and TWriter classes that perform streaming are publicly accessible and even documented. So they are clearly intended for end users as well.

现在,可能的问题是当您保存流,并且流中的其中一个类更改时,流不兼容。如果您尝试打开D7中保存的表单(缺少属性),您可能已经在Delphi中看到过。但即使发生这种情况,也不难解决。您将收到一个异常,报告导致问题的确切属性。您还必须使用 RegisterClass 注册所有要流式的类。

Now, the possible problem is when you save a stream and later one of the classes in the stream changes so that the stream is not compatible any more. You may have seen this in Delphi if you attempt to open a form saved in D2007+ in D7 (missing property). But even if it happens, it's not too hard to resolve. You will get an exception that will report the exact property that is causing the problem. You also have to register all classes that you want to stream with RegisterClass.

DFM可以以二进制或文字格式。即使您存储二进制,您可以将其转换为文本(使用 ObjectBinaryToText ),一旦以文本格式,就很容易修复。

DFM can be stored in binary or text format. Even if you store it Binary you can convert it to Text (using ObjectBinaryToText), once in text format, it's easy to fix.

所以,由于不兼容的结构变化,可能会遇到的问题,但是与DFM机制本身无关,而且也会发生任何其他流传输机制。

So, the problems you may get happen due to incompatible changes in the structure, but those have nothing to do with DFM mechanism itself, and would also happen using any other streaming mechanism.

对于长寿,您仍然可以在最新的Delphi中打开使用D1保存的DFM。所以只要你保持向后的兼容性,你没有什么可怕的。

As for longevity, you can still open DFM's saved with D1 in the latest Delphi. So as long as you keep backward compatibility in mind, you have nothing to fear.

总之,选择任何特定的格式,DFM,XML,JSON,你自己的...真的不会影响长寿。他们都需要相同的兼容性水平。

In conclusion, the choice of any particular format, DFM, XML, JSON, your own... doesn't really affect longevity. They all require same level of compatibility.

选择格式的原因与以下决定有关:

The reasons for choosing the format have more to do with decisions regarding:


  • 与其他应用/服务的互操作性

  • size / speed / human可读性

但是你没有提到任何问题。

But you didn't mention any of those in the question.

所以我建议使用DFM over roll自己的,因为这意味着更少的代码维护。

So I suggest using DFM over roll your own, as it would mean less code to maintain.

这篇关于长寿使用Delphi文本DFM格式为我自己的商店和检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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