启用Delphi XE RTTI仅适用于某些类 [英] Enable Delphi XE RTTI only for some classes

查看:298
本文介绍了启用Delphi XE RTTI仅适用于某些类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



原因是对于那些我想要RTTI的类,我想要RTTI在公共方法上,但是如果在项目范围内启用,那么所有类的所有公共方法都可以进入最终的可执行文件。
这基本上关闭了智能链接,因为编译器认为每个公共方法都可以在运行时被调用,因此最终可以编译几乎所有的东西,厨房可以进入可执行文件...



我尝试了几件事:




  • 使用<$ c关闭项目级RTTI $ c> {$ RTTI EXPLICIT METHODS([])PROPERTIES([])FIELDS([])} 然后重新启用相关单元会在编译时导致崩溃(AV某处)在$ RTTI指令中。

  • 在项目级别关闭RTTI,然后使其逐级编译,但在运行时会导致不合格的AV深入Rtti.pas当尝试访问暴露类的RTII时

  • 通过嵌入.inc中的$ RTTI指令控制RTTI所有单元在编译时使用随机AV的结果(总是在$ RTTI指令的行,但并不总是为同一个单位)。



任何其他想法?

解决方案

作为Embarcadero考虑的QC 98261提交的编译器错误。



运行时AV与属性相关,所以解决方法是确保(手动,没有编译器错误或警告)暴露类中使用的属性都有它们的RTTI,否则您得到不合格的运行时间AV。



只要$ RTTI指令在单元的单位语句之前使用编译器AV,如果你放在AV不发生并且它的工作。


I'm trying to have RTTI enabled only for a subset of my classes.

The reason is that for those classes for which I want RTTI, I want RTTI on public methods too, but if that is enabled project-wide, then all public methods from all classes get into the final executable. This basically turns off the smart-linking, as the compiler considers that every public method could be called at runtime, and thus ends up compiling pretty much everything and the kitchen sink into the executable...

I've tried several things:

  • Turning off RTTI at the project level with {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} and then re-enabling it for the relevant units results in crashes at compile time (an AV somewhere in the compiler) on the $RTTI directive.
  • Turning off RTTI at the project level and then enabling it class-by-class compiles, but at runtime it results in an unqualified AV deep in "Rtti.pas" when attempting to access the RTII for the exposed classes
  • Controling RTTI via $RTTI directives embedded in the ".inc" all units use results in random AV at compile time (always at the line of the $RTTI directive, but not always for the same unit).

Any other ideas?

解决方案

Compiler bug submitted as QC 98261 for Embarcadero consideration.

The runtime AV was related to attributes, so a workaround is to make sure (manually, there are no compiler errors or warnings) that the attributes used in the exposed classes all have RTTI for them, otherwise you get the unqualified runtime AV.

The compiler AV happens whenever the $RTTI directive is used before the "unit" statement of a unit, if you place it after the AV doesn't happen and it works.

这篇关于启用Delphi XE RTTI仅适用于某些类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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