Delphi 框架的模型 OnCreate 事件

发布于 2024-09-14 08:54:18 字数 325 浏览 9 评论 0原文

我正在开发一个Delphi框架,需要首先将业务对象列表加载到网格控件中。 Delphi 框架没有 OnCreate 事件,那么复制此事件的最佳方法是什么?我应该像 About 上建议的那样重写构造函数吗?我是否应该创建一个公共 loadData() 过程并让父容器在准备创建时调用它?

我想确保所有子控件都已加载并准备好,然后再填充数据,而且我不熟悉 Delphi 组件创建层次结构。

I am developing a Delphi frame and need to load a list of business objects into a grid control at the beginning. Delphi frames have no OnCreate event, so what is the best way to replicate this? Should I override the constructor like is suggested on About? Should I just make a public loadData() procedure and have the parent container call it when its ready to create?

I want to make sure all the child controls are loaded and ready to go before filling them with data and I am not familiar with the Delphi component creation hierarchy.

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

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

发布评论

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

评论(2

め七分饶幸 2024-09-21 08:54:18

我不会将数据填充与创建联系起来。您可以合理地创建一个框架并保留它,但稍后更改它显示的内容。如果您在 onCreate 中填充,那么您必须释放并重新创建才能获取新数据。因此,使用 LoadData() 是更好的方法。

根据应用程序的复杂性以及您拥有的表单和框架的数量,让所有框架继承一个公共基础框架可能会很方便。然后,您可以在基类中引入虚拟 LoadData 方法,并在框架子类中重写。

或者,您也可以设计一个接口并让框架实现它。如果做得正确,您可以统一处理表单、框架甚至面板等。

很难给您更具体的建议,因为这取决于 GUI 和应用程序的复杂性。一般来说,表单/框架中的逻辑/代码越少越好。因此,引入某种处理表单/框架的注册和显示的 FormManager 类可以帮助在单个位置隔离此行为。但如果它是一个小而简单的应用程序,您可以只用表单来完成它。

I would not tie populating of data to creation. You could reasonably create a frame and keep it but change the content it displays later. if you populate in onCreate then you have to free and recreate in order to get fresh data. So having a LoadData() is a better approach.

Depending on the complexity of the app and the number of forms and frames that you have, it may be handy to have all your Frames inherit from a common base frame. You could then introduce a virtual LoadData method in the base and override in frame subclasses.

Alternatively, you could also design an interface and have frames implement it. If done properly that could allow you to treat forms, frames or even panels, etc, uniformly.

It is difficult to give you a more specific advice, as it depends on the complexity of the gui and the app. In general, it is always good to have as little logic/code in forms/frames as possible. So introducing some kind of FormManager class that handles registration and display of forms/frames can help isolate this behavior in a single location. But if it's a small, simple app you can get away with just doing it in forms.

原来分手还会想你 2024-09-21 08:54:18

我通常会选择两种不同的方法之一:

  1. 重写的构造函数采用某种对象,该对象要么包含所有项目,要么知道如何获取它们(例如枚举器)
  2. 具有针对同一类型对象的设置器的属性

这样,如何获取对象的逻辑可以隐藏在其他地方。

(现在,这可能是您已经在做的事情,但是“LoadData”这个名字让我相信您的名声实际上是从某种存储库加载数据,而不是仅仅显示其他人之前获取的数据...)

I would usually choose one of two different approaches:

  1. An overridden constructor taking some kind of object which either contains all items, or know how to get them (e.g. an enumerator)
  2. A property with a setter for the same kind of object

This way, the logic of how to get the objects can be tucked away some where else.

(Now, it may be that this is what you already do, but the name 'LoadData' makes me believe that your fame is actually going to load data from some kind of storage repository instead of just displaying the data some one else has previously fetched...)

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