问题
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