Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will there be any detrimental effects if I accidentally remove something from a forms uses list which a control is referencing?

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.

like image 270
Alister Avatar asked Dec 16 '13 19:12

Alister


2 Answers

For the IDE being able to find a DataModule (for properties not once set) at design time, the following must be true:

  • The DataModule must be opened/created at least once during the session of the IDE (it may be closed afterwards during the session), see (*), and
  • The DataModule unit must be present in the uses clause of the Form unit.

For the IDE being able to find a DataModule again (for properties already set) at design time, the following must be true:

  • The DataModule must be opened/created at least once during the session of the IDE (it may be closed afterwards during the session), or
  • The DataModule unit must be present in the uses clause of the Form unit, or
  • The DataModule unit must be added to the project file.

For the program being able to find a DataModule (for properties already set) at runtime:

  • The DataModule must be created, or
  • The DataModule unit must be present in the uses clause of the Form unit.

For the program being able to find a DataModule (for properties not set) at runtime:

  • The DataModule unit must be present in the uses clause of the Form unit.

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.

like image 160
NGLN Avatar answered Sep 28 '22 05:09

NGLN


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.

like image 30
Uwe Raabe Avatar answered Sep 28 '22 05:09

Uwe Raabe