Tweaking DFM Loading (update)

In my previous article Tweaking DFM Loading I explained ways to overcome the name problem with several instances of a data module. Actually there is still another way to resolve this.

In case you didn’t already, you should read that article first to understand what I am talking about here.

The FOnFindComponentInstance checks Screen.DataModules for a data module with the name in question. If we can avoid adding our data module to that list, the name of the newly created TMainDM instance will remain unchanged.

To skip adding a TDataModule instance to the Screen.DataModules list, we need to override its CreateNew method and change the Dummy parameter to -1.

As a consequence our global instance of TMainDM will not be found for TMainForm either. Thus we need to create a local instance of TMainDM in TMainForm, too.

Now we don’t need that global instance anymore and remove TMainDM from the auto-created list in the project.

Author: Uwe Raabe

Addicted to Pascal/Delphi since the late 70's