Delphi:管理 TFrame 的多个实例

发布于 2024-10-13 13:49:43 字数 567 浏览 3 评论 0原文

这篇文章 中,解释了如何在 Delphi PageControl 中使用 TFrames 作为 TTabSheets 的替代品。

我一直在考虑一个类似的练习,上面似乎没有提供解决方案,而且我的解决方案似乎过于复杂。

要求是选项卡式界面,其中每个选项卡可以是多种不同设计之一。每个设计都作为 TFrame 实现。

由于正在设计的应用程序的性质,我们可能会在任何特定时刻打开任何框架的多个副本(每个选项卡的内容不同,但设计不同),以便用户可以比较 2/3 不同的细节项目同时。

例如,在一个会话中,我们可能会打开 3 个选项卡,全部为框架设计 A。 在另一种情况下,我们可能会打开 3 个选项卡,每个框架 A、B 和 C。

设计需要足够灵活,以便我们可以根据要求将框架添加到设计中。

目前我拥有的解决方案是使用单独的 TList 来管理我们打开的每种类型的框架,也许还有一个主 TList 来跟踪打开的选项卡。正如我所说,过于复杂。

有谁建议如何更简单地处理这个问题?

In this article there is an explanation of how to use TFrames as an alternative to TTabSheets in a Delphi PageControl.

I've been pondering a similar exercise, which the above doesn't seem to provide the solution for, and for which my solution seems to be overly complicated.

The requirement is for a tabbed interface, where each tab can be one of a number of different designs. Each design is implemented as a TFrame.

Due to the nature of the application being designed, we may have multiple copies of any frame open at any particular moment (with the content of each tab differing, but not the design) so that the user can compare the details of 2/3 different items at the same time.

For example in one session we may have 3 tabs open, all of Frame design A.
On another occasion we may have 3 tabs open each of Frame A, B and C.

The design needs to be flexible enough that we can add Frames to the design on request.

At the moment the solution that I have is to have separate TLists managing each type of Frame that we have open, with perhaps a master TList to keep track of the tabs that are open. As I said, over complicated.

Does anyone have a suggestion of how this could be handled more simply?

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

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

发布评论

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

评论(3

以酷 2024-10-20 13:49:43

我可能会省略框架实例的主 TList。

如果您需要它们,您可以通过直接询问 TPageControl 或通过每种帧类型的每个单独的 TList 来获取它们。

除此之外,你的方法听起来很合理。

I'd probably leave out the master TList of frame instances.

If you need them you'll be able to get them by interrogating the TPageControl directly or through each of your individual TLists for each frame type.

Apart from that your approach sounds reasonable.

随波逐流 2024-10-20 13:49:43

我有一个应用程序,它使用我自己的菜单控件来管理单个面板上的框架,以控制哪个框架可见。当我需要使框架可见时,我简单地为面板上的每个框架设置visible:=false,除了我想要的框架。我可以控制面板上的内容,因此我知道至少每个控件都是一个 Tframe,并且我可以通过迭代面板的 Controls 属性来访问每个帧。然后,我使用接口在主窗体和框架之间进行通信。

现在,如果您想使用标准的 Windows 选项卡式界面,您仍然可以按照您的建议使用页面控件,您知道每个 TtabSheet 上都有一个 Tframe,您可以检查它的类型并根据需要使用它。我不明白为什么您需要 Tlist,因为如果您确实需要获取“Tframe 列表”,您可以通过迭代页面控件中的 TtabSheets 来动态构建它。

另一种替代方法是使用 TtabControl 而不是 TpageControl,其工作方式与我的第一种方法类似,但可以为您提供漂亮的 Windows 选项卡。使用 TtabControl,您基本上只获得一个代表所有选项卡的 Tstrings 实例(在 Tabs 属性中)。由于它是一个 Tstring,您可以将一个对象(即您的 Tframe)与每个项目以及每个选项卡相关联。当您单击选项卡时,您会隐藏所有内容并显示正确的 Tframe。您还拥有列表,因为它通过 Tabs 属性附加到 TtabControl。您只需要自己处理框架的可见性。

I have an application that manages frames on a single panel with my own menu control to control which frame is visible. When I need to make a frame visible I simple set visible:=false for every frame on the panel except for the one that I want. I am in control of what goes onto the panel so I know that at the very least each control is a Tframe and I can get to each frame by iterating over the Panel's Controls property. I then use interfaces to communicate between my main form and my frames.

Now if you want to use a standard windows tabbed interface you could still use the page control as you have suggested, you know that each TtabSheet has a single Tframe on it and you can check it's type and work with it as required. I don't see why you'd need a Tlist because if you really need to get at the "list of Tframes" you could build it dyamically anyway by iterating over the TtabSheets in the page control.

An alternative which would work similarly to my first approach, but gets you nice Windows tabs, would be to use a TtabControl instead of a TpageControl. With the TtabControl you basically just get a Tstrings instance (in the Tabs property) which represents all of the tabs. Since it's a Tstrings you can associate an object (ie your Tframe) with each item and hence each tab. When you click a tab you hide everything and show the correct Tframe. You also have your list because it's attached to the TtabControl via the Tabs property. You just have to handle the visibility of the frames yourself.

扭转时空 2024-10-20 13:49:43

我们使用 TPageControl 并在运行时创建 TTabSheet 后代,它为我们自己的 TFrame 提供了一个新属性(我们不需要每次都扫描 .Controls 或 .Components 来搜索我们的框架)。

We use a TPageControl and create runtime a TTabSheet descendant, which has a new property for our own TFrame (we do not need to scan through .Controls or .Components to search our frame each time).

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