简体   繁体   English

Delphi - 如何从XE8开始正确注册图形类?

[英]Delphi - How to correctly register a graphic class since XE8?

I'm writing a Delphi package, which provides a new custom TGraphic object, allowing to read a new image format in VCL components like TImage. 我正在编写一个Delphi包,它提供了一个新的自定义TGraphic对象,允许在像TImage这样的VCL组件中读取新的图像格式。

I originally developed this package with RAD Studio XE7, and it worked well. 我最初使用RAD Studio XE7开发了这个软件包,效果很好。 However I migrated recently to a newer RAD Studio compiler version, and although my package continues to work properly on that new version, I noticed a strange bug that never appeared before. 但是我最近迁移到了一个较新的RAD Studio编译器版本,虽然我的软件包继续在新版本上正常工作,但我注意到一个以前从未出现的奇怪错误。

I have a form with several components, some of them are TImage components. 我有一个包含多个组件的表单,其中一些是TImage组件。 Immediately after opening the IDE, the first time I open my project in design time, all the TImage components containing my custom TGraphic component loose their content. 打开IDE后,第一次在设计时打开项目时,包含我的自定义TGraphic组件的所有TImage组件都会丢失其内容。 If I close then reopen the project, the images reappear, and the bug no longer happen until I close and reopen my IDE. 如果我关闭然后重新打开项目,图像会重新出现,并且在我关闭并重新打开IDE之前不再发生错误。

I dug in my code to understand what may cause the issue. 我挖掘了我的代码,以了解可能导致问题的原因。 To register my custom TGraphic component, I use the class initialization section, in which I wrote the following code: 要注册我的自定义TGraphic组件,我使用类初始化部分,其中我编写了以下代码:

initialization
begin
    Vcl.Graphics.TPicture.RegisterFileFormat('svg', 'Scalable Vector Graphics', TWSVGGraphic);
end;

However I found that, since the XE8 compiler version, the TImage constructor is called before my initialization section, causing thus apparently the above mentioned issue. 但是我发现,自从XE8编译器版本以来,在我的初始化部分之前调用了TImage构造函数,因此显然导致了上述问题。 All the compiler versions since XE8 are affected, but this bug never happened on XE7 or earlier. 自XE8以来的所有编译器版本都受到影响,但此错误在XE7或更早版本中从未发生过。 So something changed since XE8. 所以自XE8以来发生了一些变化。

Here are my questions: 这是我的问题:

  • Is the way I use for register my custom graphic class correct? 我用于注册我的自定义图形类的方式是正确的吗?
  • If not, what is the correct way to do that? 如果没有,这样做的正确方法是什么?
  • As something seems different since XE8, what it the new correct manner to register my graphic component? 由于XE8以来看起来有些不同,注册我的图形组件的新方法是什么?
  • Did anyone else faced the same issue? 还有其他人遇到过同样的问题吗? How he resolved it? 他是如何解决的?
  • Is this may be a new RAD Studio bug, or the issue is rather on my side? 这可能是一个新的RAD Studio错误,还是问题在我身边?

This is most likely a side effect of the smart loading the IDE applies to design time packages. 这很可能是IDE应用于设计时包的智能加载的副作用。 You can overwrite this behavior by calling ForceDemandLoadState(dlDisable) during the Register procedure of your package. 您可以通过在程序包的“注册”过程中调用ForceDemandLoadState(dlDisable)来覆盖此行为。

More about this can be found in the documentation of more recent versions of Delphi than XE8: Explicitly disabling smart loading of components in a design-time package 有关这一点的更多信息可以在更新版本的Delphi而不是XE8的文档中找到: 在设计时包中明确禁用智能加载组件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM