Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

I originally developed this package with RAD Studio XE7, and it worked well. 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.

I have a form with several components, some of them are TImage components. 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. If I close then reopen the project, the images reappear, and the bug no longer happen until I close and reopen my 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:

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. All the compiler versions since XE8 are affected, but this bug never happened on XE7 or earlier. So something changed since 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?
  • 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?
like image 898
Jean-Milost Reymond Avatar asked Jun 08 '19 15:06

Jean-Milost Reymond


1 Answers

This is most likely a side effect of the smart loading the IDE applies to design time packages. You can overwrite this behavior by calling ForceDemandLoadState(dlDisable) during the Register procedure of your package.

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

like image 171
Uwe Raabe Avatar answered Sep 25 '22 17:09

Uwe Raabe