Let's say that I have a datamodule with an ImageList. I also have a form with a button. If I wanted to hook up the ImageList property of the button, I would add the DataModule to the forms uses then select the ImageList in the Image drop-down in the button properties.
However, I can now remove the DataModule from the Forms uses list and things still seem to work fine.
Additionally, if the DataModule is open in the IDE and not in the forms uses list, I can manually type into the images property of the button the name of the image list, and it seems to correctly display the image on the button.
The Question: Will there be any detrimental effects if I accidentally remove something from a forms uses list which a control is referencing?
I am currently in the process of cleaning up the uses lists of hundreds of forms in a large project (using cnPack and Icarus) and I want to know how careful (or ruthless) I need to be.
For the IDE being able to find a DataModule (for properties not once set) at design time, the following must be true:
For the IDE being able to find a DataModule again (for properties already set) at design time, the following must be true:
For the program being able to find a DataModule (for properties already set) at runtime:
For the program being able to find a DataModule (for properties not set) at runtime:
Thus, theoretically, if all the right conditions are met, your DataModule unit could be omitted from the uses clause of the Form. But to be confident of runtime linkage, I would conclude that there is no safe or at least no convenient escape from adding the DataModule unit to the Form unit's uses clause.
(*) In large projects with many Forms and DataModules, it is very common to not open every DataModule in the IDE, and settings easily can get lost. Being dependent on the designtime binding by DataModule name then may result in your Forms never showing any data (or Images in this case). This is a bug which is hard to foresee whithout checking every Form's DataModule settings.
A solution to that is to set all properties which refer to a DataModule's components manually at runtime, preferably in an overriden constructor or in an OnCreate event handler. This also prevents duplicate naming issues with multiple DataModule instances, as this question deals with.
The linking of component properties (like Images) is independent of a suitable entry in the uses list. The magic is hidden inside the streaming system (look for xxxFixUpReferences). As long as the compiler is not complaining you can safely remove those entries.
It is still possible that the IDE might not be happy with that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With