在 Delphi 中使用框架的公认方式是什么?
我像往常一样四处闲逛,偶然发现了一些框架讨论。
我主要是一名 Delphi 爱好者而不是专业人士,所以我必须学习如何以自己的方式使用 TFrame,即:
- 在其单元内创建一个 TFrame。
- 将该单元添加到主窗体 Uses 子句中。
- 有一个该 TFrame 类型的私有变量
- OnCreate 形式实例化 TFrame 并将其附加到 TPanel 上的 Create 和 .Parent
- 在我的操作之一上设置 TFrame.Visible := True 和 .BringToFront。
这是我个人深思熟虑后的做法。
还可以通过哪些其他方式使用框架?
I was having my usual stroll around and bumped on some frames discussions.
I'm mainly a Delphi hobbyist and not a professional, so I had to learn how to use TFrames my own way which is:
- Create a TFrame inside its unit.
- Add that unit to the main form Uses clause.
- Have a private variable of that TFrame's type
- OnCreate of the form instanciates the TFrame and attaches it to a TPanel both on the Create and .Parent
- On one of my Actions set that TFrame.Visible := True and .BringToFront.
This is my practice after some personal deliberation.
What other ways can one use the frames?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一种方式,而且没有什么问题。另一种方法是通过视觉来完成。所以你基本上可以将框架添加到表单中。为此,您:
That's one way, and there is nothing wrong with it. Another way, is to to do it visually. So you can basically add the frame to a form. to do this you :
您的方法的唯一问题是您无法将同一帧的多个实例添加到给定的表单中:
他的解决方法是为每个实例分配不同的名称:
编辑:也可以为名称分配一个空字符串,因此您无需为每个实例起一个唯一的名称。
The only problem with your approach is that you cannot add multiple instances of the same frame to a given form:
The workaround for his is to assign a different name for each instance:
Edit: It's also possible to assign an empty string for the name, so you don't need to come up with a unique name for each instance.
您甚至可以更进一步,将框架注册为组件。
一旦框架组件位于窗体上,您就无法编辑框架上组件的属性。但我认为这是一件好事。
除了将框架注册为组件之外,您还需要做一件事,正如我在这篇关于 Delphi – 框架作为可视化组件 – 不要忘记你的 Sprig!。
这些知识不是我的:我从 Ray Konopka 那里得到的他在今年早些时候在圣何塞举行的 Delphi Live 会议。
You can even go a step further, by registering your frames as components.
That disallows you to edit properties of components on the Frame as soon as the Frame component is on the form. But I think that is a good thing.
You need to one more thing than registering your frame as a component, as I explain in this article about Delphi – Frames as visual Components – don’t forget your Sprig!.
That knowledge is not mine: I got it from Ray Konopka during one of his sessions at the Delphi Live conference in San Jose earlier this year.
这更像是一个否定的答案,但我尝试了一种方法,其中包括为有点复杂的 GUI 重新设置 TFrame 的父级。
起初一切顺利,但当应用程序成熟并且更多事件开始发生时,我不得不在更改之前禁用并处理消息一段时间(20毫秒),然后在更改框架时仍然偶尔会崩溃。
我最终发现的罪魁祸首之一是,TPopmenu 也在全局数据结构中注册了自己。这减少了问题,但问题仍然存在,所以我放弃了这个概念。
This is more a negative answer, but I tried a route that included reparenting TFrames for a bit complex GUI.
At first it went fine, but when the application matured and more events started flying, I had to disable and then process messages for a while (20ms) before changing, and then still occasionally had crashes when changing frame.
One of the culprits I eventually found, TPopmenu also registers itself in global datastructures. This reduced the problems, but they were still there, so I move away from the concept.