Please have a look to the attached sample projects (delphi 10.4.2 with TMS Scripter 7.24).
It includes:
a Dll project that only have IDEMAIN in dependency and do nothing
a exe that only load the dll then exit
Execute the project in the Delphi debugger, an access violation occurs in TWICImage.Destroy calling FImagingFactory._release while FImagingFactory is not nil.
If the IDEMAIN dependency is removed, the access violation disappear.
I tried to reproduce without IDEMAIN dependency, with TDBNavigator or TDBGrid, in these cases the TWICImage.Destroy was called but did not crashed.
It seems something goes wrong when using IDEMAIN in a dll.
I'm afraid it's a Delphi bug. After hours spent trying to figure out what's going on, we discovered that using DBGrids unit instead of IDEMain unit causes the same issue. There isn't much we can do.
On my side, with the attached sample, if I replace the IDEMAIN dependency by the DBGrids dependency, I cannot reproduce.
How did you reproduce ?
Did you create a bug on Enbarcadero Quality Central ?
Indeed changing directly your original code doesn't reproduce the issue. But after hours and hours we end up to that scenario. No QC report especially because it's hard to isolate, indeed. But looks like a bug.
We have actually modified FormDesigner.pas source code to workaround the issue, so that the problem doesn't occur anymore - well at least with your project. Who knows if the problem will reappear as your project increases in complexity.