11
votes

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?
1
Is your package registered into the IDE before you open the form with the images?Uwe Raabe
Yes, it is. I compile and install the package, then I close and reopen the IDE, and as soon as the project is opened in design time for the first time, the issue happen.Jean-Milost Reymond
Presumably, the TImage constructor is being called in an initialisation section before yours(?). Have you tried observing the behaviour by debugging one instance of the IDE inside another?MartynA
Yes I also did that, it's in fact the reason why I said that the TImage constructor is called before the graphic registration, because I observed this behavior. The issue happen in a demo project, which contains the above mentioned form, containing itself several TImages, all placed in design time. The graphic registration initialization section is located in a class on the package side, however. But I never instantiated any TImage inside any initialization block, neither in package nor in demo code.Jean-Milost Reymond
@Jean-MilostReymond definitely sounds like an IDE bug. Your approach is fine. Packages that your project depends on should be fully loaded before any Forms are loaded. Please file a bug report with Embarcadero.Remy Lebeau

1 Answers

9
votes

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