How can I assign a .NET 4 WinForm application to the owner property of a Delphi 7 form?

孤街浪徒 提交于 2020-01-14 03:10:28

问题


I need to assign a .NET 4 Winform application as the owner of a Delphi 7 form.

I have created a .dll in Delphi which contains the form. The Delphi .dll exports methods to create and display the form.

I have successfully loaded the Delphi .dll in my .NET app, and displayed the form.

Now I need to be able to assign the .NET app (or main form of the .NET app) as the owner of the Delphi form.

I have previously created a Delphi app that interops to .NET through COM, and assigns the Delphi app as the owner of the .NET forms using the following class:

public class WindowHandleWrapper : IWin32Window
{
    public HandleRef m_Handle;

    public IntPtr Handle
    {
        get
        {
            return m_Handle.Handle;
        }
    }

    public WindowHandleWrapper(IntPtr handle)
    {
        m_Handle = new HandleRef(this, handle);
    }
}

The Delphi application handle was passed as an integer to the WindowHandleWrapper constructor.

I suspect that the solution will be something similar, e.g. passing a handle to Delphi as an integer. However, the Delphi type for the Owner property of a form is TComponent. I'm just not exactly sure how to assign the .NET handle as the Delphi form's owner.

Any ideas?


回答1:


Pass your WinForm handle to the DLL as a parameter, and assign it to Application.Handle before creating and showing the form modally.



来源:https://stackoverflow.com/questions/5249468/how-can-i-assign-a-net-4-winform-application-to-the-owner-property-of-a-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!