Welton v3.64
Welton v3.64

Reputation: 2230

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

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?

Upvotes: 1

Views: 734

Answers (1)

Ondrej Kelle
Ondrej Kelle

Reputation: 37221

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

Upvotes: 6

Related Questions