7
votes

Is there a way to create an MDI child window from an ActiveX dll written in Delphi 5, and to embed it in a MDI parent window created from a Delphi XE windows client application? If not, is there a way to mimic the behavior?

Background

There is an application written entirely in Delphi 5. The main form of the application is an MDI parent window. All other forms in the application are MDI child forms, and every one of them is created from an ActiveX library. The parent application creates the ActiveX, after which is calls a method of the ActiveX interface. From this method a form is created and it's FormStyle is set to fsMDIChild. At this point the form is an MDI child of the MDI parent. This works because both the application and the ActiveX libraries are compiled using runtime packages. As a result, all forms share the same instance of TApplication.

The Problem

The application is very large, and needs to be migrated to Delphi 2010 or Delphi XE. It would be fantastic if the application could be migrated systematically, by first migrating the application, and then migrating the ActiveX libraries one at a time (there are about 50 of them).

The problem is that if the console application is compiled in XE, it will no longer be using the same TApplication instance as those libraries still compiled in Delphi 5.

Even if the forms in the ActiveX library cannot be true MDI child windows, it seems like I should be able to return the handle of the form that is created from the ActiveX and grab it from the main form and make the form appear to be an MDI child. I could then create my own layer for handling events.

Any ideas?


Update: The approach currently being taken with this application is that it is being migrated from MDI to an SDI interface. It is perfectly possible to instantiate TForms from a Delphi 5 ActiveX DLL from a Delphi XE application, so long as the first form from each DLL can take care of it's own data (loading, saving, displaying additional forms, etc). The problem was in keeping the original MDI design. If the SDI design proves acceptable, there will be no need for an MDI solution. Still, if someone knows how to accomplish the MDI solution, I'd like to know.

2
You could perhaps embed the forms from the activex library in MDI child forms created in the XE app... (re-parenting the activex forms into the XE instantiated forms - and don't change the activex forms' form style)Marjan Venema

2 Answers

4
votes

Originally, I said that you cannot create do so. I researched some more and found out that it's possible to do it. You have to be very careful though.

Here's some source I created recently to test out the idea: http://cc.embarcadero.com/item/28168

The code spawns the Windows Calculator and Notepad app, then MDIize the external windows into the MDI Form.

Click Launch Notepad after starting the app, and see what happens.

You should be able to modify the work further so that you can achieve what you need.

Note that you need to ensure that your MDI Child in the ActiveX DLL is entirely self-contained.

0
votes

Even if the forms in the ActiveX library cannot be true MDI child windows, it seems like I should be able to return the handle of the form that is created from the ActiveX and grab it from the main form and make the form appear to be an MDI child. I could then create my own layer for handling events.

I'd try something like this (inspired by Marjan's comment):
in the Delphi 5 MDI windows, split the Window in two layers for each of forms:

  • a set of frameless TForms/TFrames having the content (maybe expose this as an ActiveX forms)
  • for each frameless content, one MDI child that handles the MDI

in the Delphi XE host:

  • obtain the handle for each of the Delphi 5 frameless TForms/TFrames
  • embed that handle in an MDI child form

It probably means you have to duplicate part of the Delphi 5 MDI handling in Delphi XE.

--jeroen