Delphi 新 RTTI 的实际使用 - Attributes,Values [英] Practical usage for Delphi's new RTTI - Attributes,Values

查看:20
本文介绍了Delphi 新 RTTI 的实际使用 - Attributes,Values的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了一个 关于 Delphi 中新 RTTI 的很好解释,但我不明白我读过的所有内容中的一件重要事情 - 我在哪里可以使用它?

I found a great explanation about the new RTTI in Delphi,but I don't understand one important thing about all I have read - Where can I use that?

它应该取代什么?

推荐答案

扩展的 RTTI 的工作方式类似于 .NET 中的反射.它使您可以访问内部应用程序结构信息.您可以在运行时访问类属性、方法等,在一定程度上您以前无法做到.

The extended RTTI works like Reflection in .NET. It gives you access to your internal application structure information. You can access class properties, methods etc.. at runtime, at extent you could not do it before.

一些使用方法:

  1. 将类序列化/反序列化为 XML 或其他媒体
  2. 将对象映射到数据库.ORM.
  3. 克隆对象
  4. 动态调用方法
  5. 在运行时扫描"对象并据此执行操作.
  6. 更轻松地开发插件"类型系统

可能有很多场景使用它是有益的.简而言之,它为您的应用程序添加了动态方面.您的产品能够在运行时做一些事情,而且比在设计时设计所有东西更有效.它不是灵丹妙药,很多人可能永远不会使用它.但是一些设计模式或一些问题,如果不使用新的 RTTI 就无法解决(至少不是以有效的方式)

There is probably a lot of scenarios where it would be beneficial to use it. In short it adds dynamic aspect to your application. Your product is able to do some things at runtime, and more efficiently, than designing everything at designtime. It is not a silver bullet and a lot of people may never use it. But some design patterns or some problems just cannot be solved (at least not in efficient way) without the use of the new RTTI

这篇关于Delphi 新 RTTI 的实际使用 - Attributes,Values的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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