Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create an MDI child window from a Delphi 5 ActiveX dll, and embed it in a Delphi XE MDI parent?

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.

like image 899
Cary Jensen Avatar asked Dec 10 '10 19:12

Cary Jensen


1 Answers

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.

like image 144
chuacw Avatar answered Nov 15 '22 11:11

chuacw