DLL 中新窗体的父级设置问题

发布于 2024-07-18 08:33:11 字数 449 浏览 4 评论 0原文

请解释一下两者之间的区别:

ChildForm := TForm.CreateParented(AOwner)

ChildForm := TForm.CreateParentedControl(AOwner)

ChildForm := TForm.Create(AOwner); 
ChildForm.ParentWindow := AOwner.Handle 

这个示例可能很复杂且令人费解,我真的只是想概述一下人们何时使用不同类型的表单创建方法。

Delphi 7 帮助告诉我,我应该使用 CreateParented(AOwner.Handle) 和 ParentWindow := AOwner.handle 与非 VCL 控件或跨 DLL。 直到昨天我才设置 Parent := AOwner ,我完全不知道为什么它停止工作。

(也许我只需要重新启动计算机)

Please explain the difference between:

ChildForm := TForm.CreateParented(AOwner)

ChildForm := TForm.CreateParentedControl(AOwner)

ChildForm := TForm.Create(AOwner); 
ChildForm.ParentWindow := AOwner.Handle 

This example may be complicated and convoluted, I'd really just like an overview of when people use the different kinds of Create methods for forms.

Delphi 7 help tells me that I should use CreateParented(AOwner.Handle) and ParentWindow := AOwner.handle with non-VCL controls or across DLL's. Until yesterday I just set Parent := AOwner, and I have absolutely no idea why this stopped working.

(Maybe I just need to reboot my computer)

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

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

发布评论

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

评论(1

掩耳倾听 2024-07-25 08:33:11

我们有组件。 它们是表单或数据模块上可见或不可见的项目。 每个组件都可以有一个负责最终销毁的所有者。 如果没有主人,则必须自行负责销毁。

我们有控件,它们是可见的组件。 他们还有一个包含控件的父级。 例如,面板是该面板上按钮的父级。

我们还有 WinControls,它们是链接到 Windows 对象的控件。 它们还有父窗口的句柄。

所以:

  1. TMyControl.CreateParented
    构造函数 CreateParented(ParentWindow: HWnd);

    这用于创建一个控件,该控件的父窗口由句柄提供。
    它创建没有所有者的控件并将父窗口设置为 ParentWindow。

  2. TMyControl.CreateParentedControl
    类函数CreateParentedControl(ParentWindow: HWND): TWinControl;

    创建没有所有者的控件,将parentwindow设置为ParentWindow并返回
    它。

  3. TMyControl.Create(AOwner: TComponent)

    创建所有者设置为 AOwner 的控件。

  4. TMyControl.ParentWindow := AOwner.Handle;

    将父窗口(句柄)设置为 AOwner 的句柄。

We have Components. They are visible or invisible items on a form or a datamodule. Each component can have an owner that is responsible for the eventual destruction. If there is no owner, you must take care of the destruction yourself.

We have Controls, which are components that are visible. They also have a Parent which contains the control. For example a Panel is the parent of a button on that panel.

We also have WinControls which are controls that link to windows objects. They also have a handle of the parent window.

So:

  1. TMyControl.CreateParented
    constructor CreateParented(ParentWindow: HWnd);

    This is used to create a control from which the parent window is provided by an handle.
    It creates the control without owner and sets the parentwindow to ParentWindow.

  2. TMyControl.CreateParentedControl
    class function CreateParentedControl(ParentWindow: HWND): TWinControl;

    Creates the control, without owner, sets the parentwindow to ParentWindow and returns
    it.

  3. TMyControl.Create(AOwner: TComponent)

    Creates a control with owner set to AOwner.

  4. TMyControl.ParentWindow := AOwner.Handle;

    Sets the parentwindow (handle) to the handle of AOwner.

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