Opening a Delphi.NET MDI Child Form  in a C# application

Posted on 2007-10-08
Last Modified: 2013-11-23
This could be a difficult one, so please bear with me.

I've an assembly containing Delphi 2006.NET forms.

A C# app, via reflection opens these forms . This works fine - I've a C# app, opening Delphi 2006.NET forms.

Some of these forms are MDI Child forms. Exceptions are thrown - "Cannot create form - No MDI Forms are currently active" when the C# app tries to open one of these.

The C# app does have the property MDI Container = True. I realise it is the Form that I'm trying to create throwing the exception, rather than the C# application - the Delphi Form expects the opening form to be of form style fsMDIForm.

Does anyone know of a way around this? i.e. I want the MDI children (delphi forms) to be happy about opening in a C# application whose main form is an MDI Container.

I really, really, really, really need to be able to do this. Hope some genius is out there....


Question by:steve-west
    LVL 21

    Expert Comment

     Are you using these forms from another application (Delphi based) as well?  If they are used by one application you can simple make them non MDI.  For now I will assume that it is not that easy...

      You could create a TStream class to read in the MDI forms.  The primary reason for creating this class would be to ignore any attempts to set the MDI related properties.  You would likely need to look at the Delphi source and watch how it is done there.  

    I honestly do not have the time to make an example right now.

    Let me know if you need more.

    Author Comment

    Yes, the forms are used from another application - a Delphi Win32 app.

    Due to customer demand, we're - I'm - developing a .NET version of our application suite. The main form has to be written in C# since we're lacking a Delphi.NET version of one of the main interface components, but a C# equivalent is available.

    Each application loads its screens from external packages. The Delphi Win32 ad the C# app share screens (around 3000), all of which are written in Delphi 2006, but compiled into Win32/.NET libraries.

    This works fine but for the aforementioned MDI children.

    You mention streams to read in the MDI forms. Whilst I have extensive  experience of delphi, you've completely lost me as to how this applies to loading a form via .NET reflection. Admittedly, I'm still learning C# and the .NET framework, but  I don't understand what you're suggesting, let alone how to implement it.



    Author Comment

    Right then.

    I'm fairly sure that it's not possible to host a MDI child form in a foreign application.

    So, thinking about this from another direction, is it possible to "embed" the form in a C# window, using a panel or something similar?

    For example - the C# app needs to create a form. I'm thinking along the lines of creating a regular c# mdi child, and then embedding the form within the C# form (obviously adjusting the delphi forms formstyle to be non mdi).

    Would this work and if so how?
    LVL 21

    Accepted Solution

     As far as I understand it, and I must admit that I have not tried to do what you are attempting, the Reflection code is what is handling creating your form.  Delphi forms are created by reading in an XML like stream of information that defines the form.  If you could override the code doing the reflection, that may be where you would be able to turn off (ignore) the setting of MDI child properties.  

      As to the idea of being able to embed the child form in a C# window, it should work as long as you can make it an MDI parent window.  That should be a simple property setting on the window that you want to use.  Generally this would be a form though.

    Let me know if any of this helps.

    Author Comment

    I've worked through an example which will allow me to do what I want.

    For MDI Child delphi forms, I create a C# MDI Child and reparent the delphi form once it's been loaded from the assembly. The delphi form has its caption hidden, client area maximized and borders turned off so that it fills the client area of the C# sharp form. I  still need to implement a certain amount of interaction between the delphi form and its host (for example, caption changing, form closing etc), but it **should** work as I want.

    Thanks for all suggestions.



    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
    This video discusses moving either the default database or any database to a new volume.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now