Take the 2-minute tour ×

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
            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?

share|improve this question
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 Mar 9 '11 at 17:24
Those reasons have nothing to do with Owner, in Delphi terms. You mean Parent. +1 @jachguate –  TOndrej Mar 9 '11 at 17:31
@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 Mar 9 '11 at 17:37
Yes, after reading his comment, perhaps he just needs to assign the winform handle to Delphi's Application.Handle. –  TOndrej Mar 9 '11 at 17:44
@Ken White: nil Owner works. –  TOndrej Mar 9 '11 at 17:50
show 11 more comments

1 Answer

up vote 6 down vote accepted

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

share|improve this answer
That is exactly what I was looking for. Sorry for the confusion. –  Welton v3.53 Mar 9 '11 at 17:52
It's a very old trick for showing a Delphi form from a DLL. I'm glad it helped you, cheers. –  TOndrej Mar 9 '11 at 17:53
I worked on a project that used this technique extensively as a way to modularize the application. Each dll was practically an application unto itself. All the forms ran full screen modal and certain UI elements were standardized so it gave the appearance that it was a single form updating dynamically based on the user's actions. –  Kenneth Cochran Mar 10 '11 at 18:31
add comment

Your Answer


