如果我不小心从控件引用的表单使用列表中删除了某些内容,将会有不利影响吗? [英] Will there be any detrimental effects if I accidentally remove something from a forms uses list which a control is referencing?

查看:92
本文介绍了如果我不小心从控件引用的表单使用列表中删除了某些内容,将会有不利影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个带有ImageList的数据模块。我也有一个带有按钮的表格。如果要挂接按钮的ImageList属性,可以将DataModule添加到使用的表单中,然后在按钮属性的图像下拉列表中选择ImageList。



但是,我现在可以从Forms Uses列表中删除DataModule了,事情似乎仍然可以正常工作。



另外,如果DataModule在IDE中打开,而不是在表单使用列表中,我可以手动在按钮的images属性中键入图像列表的名称,似乎可以正确在按钮上显示图像。



问题:如果我不小心从控件引用的表单使用列表中删除了某些内容,将会有不利影响吗?



我目前正在清理中大型项目(使用cnPack和Icarus)中数百种形式的使用列表,我想知道我需要多么小心(或无情)。

解决方案方案

为了使IDE能够找到DataModule(对于未在设计时设置过的属性),必须满足以下条件:




  • 必须至少在一次打开/创建DataModule一次。 IDE的会话(此会话之后可能会关闭),请参见(*),

  • DataModule单元必须位于



为使IDE在设计时能够再次找到DataModule(针对已设置的属性),必须满足以下条件:是真的:




  • 在IDE会话期间必须至少打开/创建一次DataModule(此后可能会在会话期间将其关闭) ),

  • DataModule单元必须出现在Form单元
  • $ b的uses子句中$ b
  • 必须将DataModule单元添加到项目文件中。



要使程序能够找到DataModule(用于属性已设置)在运行时:




  • 必须创建DataModule,

  • DataModule单元必须出现在Form单元的uses子句中。



对于程序能够在运行时查找DataModule(针对未设置的属性):




  • DataModule单元必须出现在Form单元的uses子句中。



因此,从理论上讲,如果满足所有正确的条件,则可以从Form的uses子句中省略您的DataModule单元。但是,对运行时链接很有信心,我得出的结论是将DataModule单元添加到Form单元的uses子句中并没有安全的方法,或者至少没有方便的方法。 b b $ b




(*)在具有许多Forms和DataModules的大型项目中,通常不要在IDE中打开每个DataModule,并且很容易丢失设置。然后,依赖于DataModule名称的设计时绑定可能导致您的Forms从不显示任何数据(在这种情况下为Image)。这个错误很难预见,而无需检查每个Form的DataModule设置。



一种解决方案是在运行时手动设置所有引用DataModule组件的属性,最好在重写的构造函数中或在OnCreate事件处理程序中。这也可以防止多个DataModule实例出现重复的命名问题,因为此问题可以处理。


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:

  • 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.

这篇关于如果我不小心从控件引用的表单使用列表中删除了某些内容,将会有不利影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆