如何使用私有数据模块与全局实例

发布于 2025-01-21 15:28:48 字数 352 浏览 0 评论 0原文

我有一个用于使用全局实例的框架的数据阀。(DMDATA) 数据组件已链接到DMDATA实例上的数据源,

现在我想使用一个私有框架的dataModule实例,因为我想具有同时显示框架的多个表单中的实例。

我不知道如何在代码或设计中实现这一目标。

在框架中,我将Datamodule创建为DMlocalData:= tdmdata.create(self),但是在设计中,我没有链接dmlocaldata的选项,只有链接到dmdata的选项(我所有的数据控件都是空白(因此除了具有在代码中设置的本地数据源的那个,

我的意思是,我可以在代码中手动浏览每个组件并更改数据源,但是认为确实必须有更好的方法,即维护这几乎是可怕的

I have a datamodule for my frame, which uses a global instance.(dmData)
The data components are linked to the datasources on the dmData instance

now I want to use a datamodule instance that is private to a frame, because I want to have multiple instances of the form which contains the frame showing at the same time.

I can't figure out how to make that happen, either in code or in designing.

in the frame, I am creating the datamodule as dmLocalData := tdmData.Create(self), but in design I don't have the option to link dmLocalData, only the option to link to dmData(so all my data controls are blank (except for that ONE that has a local datasource that gets set in code)

I mean, in code, I could manually go through each component one by one and change the datasource, but thinking there really has to be a better way, the maintenance on that would be pretty much horrendous.

Any ideas about a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缱绻入梦 2025-01-28 15:28:48

实际上,有一种方法可以避免动态创建的数据模块的控制。简而言之 - 覆盖datamodules createNew 构造函数类似:

constructor TMainDM.CreateNew(AOwner: TComponent; Dummy: Integer);
begin
  Dummy := -1;
  inherited;
end;

这避免了数据amodule的多个实例获得不同的名称,因此参考可以按预期解决。由于数据阀无论如何都是私有的,因此它们不需要拥有全球唯一的名称。

在这两篇文章中可以找到更长,更详细的解释,其中使用非常相似的任务为例:

调整dfm loading(update)

调整DFM加载

Actually there is a way to avoid hand-wiring the controls for a dynamically created datamodule. In short - override the datamodules CreateNew constructor like this:

constructor TMainDM.CreateNew(AOwner: TComponent; Dummy: Integer);
begin
  Dummy := -1;
  inherited;
end;

This avoids that multiple instances of the datamodule get different names and thus the references are resolved as expected. As the datamodules are private to the frame anyway, there is no need for them to have globally unique names.

A much longer and more detailed explanation can be found in these two articles, which use a quite similar task as an example:

Tweaking DFM Loading (update)

Tweaking DFM Loading

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文