1
votes

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
What's wrong with MyForm := TMyForm.Create(Application)?David Heffernan
Maybe OP is confused between Owner and parent... @Welton, I have to ask, why do you want the .NET winform to be the owner and not the parent of the Delphi form?jachguate
Those reasons have nothing to do with Owner, in Delphi terms. You mean Parent. +1 @jachguateOndrej Kelle
@TOndrej I don't think the form wants to be parented at all. OP wants a top-level window, that doesn't appear in the taskbar. And a modal form. Problem is you need to disable the forms in the .net app.David Heffernan
Yes, after reading his comment, perhaps he just needs to assign the winform handle to Delphi's Application.Handle.Ondrej Kelle

1 Answers

6
votes

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