将表单的第二个实例绑定到数据模块的第二个实例? [英] Binding a second instance of a form to a second instance of a data module?

查看:140
本文介绍了将表单的第二个实例绑定到数据模块的第二个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,它具有与数据模块中数据集绑定的数据感知控件。我需要在同一个应用程序中创建表单和数据模块的其他实例。



我删除了当数据模块首次添加到项目。令我高兴的是,设计人员的控件仍然可以绑定到数据模块中,而不需要这个全局变量。我假设IDE正在解析数据模块的dfm,所以设计人员仍然可以查看数据模块。 (没有在IDE中加载数据模块,数据源列表为空)



当我在运行时创建两个表单实例和数据模块的两个实例时,两个实例的形式似乎只绑定到创建的第一个数据模块。检查数据模块的第二个实例显示, Name 属性在设计时没有数字后缀。



表单取决于数据模块中的大量数据集。有没有更简单的方法来将第二个表单实例绑定到第二个数据模块的数据集,而不需要为每个单个控件手动编码 SomeControl.DataSource:= Module2.dsSomeData p>

我也可以选择其他建议。一个解决方案是将数据集移动到表单本身。如果设计时间数据绑定只适用于单身人士,似乎仍然是一种耻辱。

解决方案

看看这个问题:

使用delphi中的数据模块分离数据集实例



基本上,答案是创建DataModule,然后创建Form,然后将创建的DataModule的名称设置为空字符串。这将使初始数据绑定发生,但会阻止其他表单看到该模块。



此外,创建的下一个版本仍将具有原始名称(不需要数字后缀)。


I have a Form which has data aware controls bound to datasets in a datamodule. I need to create additional instances of both the form and datamodule in the same application.

I deleted the global variable that was automatically created when the data module was first added to the project. To my delight, controls in the designer could still be bound to datasets in the data module without this global variable. I'm assuming the IDE is parsing the dfm of the datamodule so the designer can still "see" the datamodule. (without the data module loaded in the IDE the list of data sources is empty)

When I create two instances of the form and two instances of the datamodule at runtime both instances of the form appear to be bound to only the first data module that was created. Inspecting the second instance of the data module reveals that the Name property has a number suffix that wasn't there at design time.

The form depends on a lot of datasets in the data module. Is there an easier way to bind the second form instance to the second data module's datasets without resorting to hand coded SomeControl.DataSource := Module2.dsSomeData for every single control?

I'm open to alternative suggestions as well. One solution would be to move the datasets to the form itself. Still it seems a shame if design time data binding only works on singletons.

解决方案

Take a look at this question:
separate dataset instances using datamodules in delphi

Basically the answer is to create your DataModule, then your Form, then set the name of the created DataModule to an empty string. That will let the initial data binding happen but prevent other forms from seeing that Module.

In addition the next version that is created will still have the original name (no need for the numeric suffix).

这篇关于将表单的第二个实例绑定到数据模块的第二个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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