如何在 Borland VCL 中获取组件的父窗体?

发布于 2024-09-03 04:04:19 字数 280 浏览 3 评论 0原文

我想确定给定组件在我的应用程序中属于哪种形式。 Parent 和 Owner 属性都不能被假定为表单本身,因此我不能简单地使用它。

我想我可以递归地遍历 Parent 属性,直到得到从 TForm 派生的东西,但是有没有更好的方法来做到这一点?我使用了搜索功能,但找不到任何特定于我的问题的内容。

顺便说一句,我正在使用 Borland C++ Builder(标记为 Delphi,因为大多数 VCL 用户似乎都是用 Delphi 编写的,而且我可以很好地阅读 Delphi 代码)。

提前致谢!

I'd like to determine which form a given component belongs to in my application. Neither the Parent nor the Owner property can be assumed to be the form itself, so I can't simply use this.

I guess I could just go through the Parent property recursively until I arrive at something derived from TForm, but is there a better way to do this? I used the search function, but couldn't find anything specific to my problem.

I'm using Borland C++ Builder, by the way (tagged Delphi because a majority of VCL users seem to write in Delphi, and I read Delphi code just fine).

Thanks in advance!

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

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

发布评论

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

评论(1

余生一个溪 2024-09-10 04:04:19

您可以在 Forms 单元中使用 GetParentForm - VCL 也经常使用它。它执行您提到的操作 - 递归地在其父项中查找第一个 TCustomForm 。此外,它还处理设计时间。

You could use GetParentForm in Forms unit - it's used by the VCL a lot, too. It does what you mentioned - recursively find the first TCustomForm in its parents. In addition, it also handles design time.

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