在 Delphi 中使用框架的公认方式是什么?

发布于 2024-08-05 18:22:14 字数 358 浏览 7 评论 0原文

我像往常一样四处闲逛,偶然发现了一些框架讨论。

我主要是一名 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 技术交流群。

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

发布评论

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

评论(4

倾听心声的旋律 2024-08-12 18:22:14

这是一种方式,而且没有什么问题。另一种方法是通过视觉来完成。所以你基本上可以将框架添加到表单中。为此,您:

  • 创建您的框架。
  • 转到您想要放置框架的表格。
  • 添加框架组件(标准选项卡)
  • 从下拉列表中选择您的框架。
  • 就是这样!

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 :

  • Create your Frame.
  • Go to the form you wish to put your frame on.
  • Add a Frames component (Standard Tab)
  • Choose your frame from the drop down.
  • That's it!
耳根太软 2024-08-12 18:22:14

您的方法的唯一问题是您无法将同一帧的多个实例添加到给定的表单中:

Frame1 := TMyFrame.Create(Self);
Frame1.Parent := Self;
// ...
Frame2 := TMyFrame.Create(Self); // bombs out with "a component with the name MyFrame already exists"

他的解决方法是为每个实例分配不同的名称:

Frame1 := TMyFrame.Create(Self)
Frame1.Parent := Self;
Frame1.Name := "FirstFrame";
// ...
Frame2 := TMyFrame.Create(Self); // works now, there is no name conflict

编辑:也可以为名称分配一个空字符串,因此您无需为每个实例起一个唯一的名称。

The only problem with your approach is that you cannot add multiple instances of the same frame to a given form:

Frame1 := TMyFrame.Create(Self);
Frame1.Parent := Self;
// ...
Frame2 := TMyFrame.Create(Self); // bombs out with "a component with the name MyFrame already exists"

The workaround for his is to assign a different name for each instance:

Frame1 := TMyFrame.Create(Self)
Frame1.Parent := Self;
Frame1.Name := "FirstFrame";
// ...
Frame2 := TMyFrame.Create(Self); // works now, there is no name conflict

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.

じ违心 2024-08-12 18:22:14

您甚至可以更进一步,将框架注册为组件。

一旦框架组件位于窗体上,您就无法编辑框架上组件的属性。但我认为这是一件好事。

除了将框架注册为组件之外,您还需要做一件事,正如我在这篇关于 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.

南街九尾狐 2024-08-12 18:22:14

这更像是一个否定的答案,但我尝试了一种方法,其中包括为有点复杂的 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.

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