Delphi 框架的模型 OnCreate 事件
我正在开发一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会将数据填充与创建联系起来。您可以合理地创建一个框架并保留它,但稍后更改它显示的内容。如果您在
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 aLoadData()
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.
我通常会选择两种不同的方法之一:
这样,如何获取对象的逻辑可以隐藏在其他地方。
(现在,这可能是您已经在做的事情,但是“LoadData”这个名字让我相信您的名声实际上是从某种存储库加载数据,而不是仅仅显示其他人之前获取的数据...)
I would usually choose one of two different approaches:
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...)