3
votes

I have an big MDI application developed with Delphi 5, and I need to add more new features, and new forms are in DLL with Delphi XE.

I have a very good example by Raymond Alexander, which works great on Delphi 5, but in trying to follow his example in my project, the DLL with Delphi XE not working properly, and gives me an error on the part of when I pass as a parameter the object "APPLICATION" and the DLL is not correctly received.

function Modulo_PPtos_Configuracion(No_Orden : Integer; PathDB : WideString ;        PathDBConfig : WideString ; App : TApplication; Scr : TScreen) : Integer ; StdCall;
begin 
  if not Assigned(DmDatos) then
   Abrir_BasesDeDatos(No_Orden, PathDB, PathDBConfig);

 if not (assigned(frm_Configuracion)) then
  begin
{$IFDEF MDI}
  **Application := App;
SHOWMESSAGE(APPlication.MainForm.Name);
   frm_Configuracion := Tfrm_Configuracion.Create(Application.MainForm);**
{$ENDIF}

{$IFNDEF MDI}
   frm_Configuracion := Tfrm_Configuracion.Create(nil);
{$ENDIF}  
end;

As you will notice when doing a debug displays a message, and where it fails, because the original failed to debug the following line of code.

Please excuse my English.

2

2 Answers

6
votes

This approach cannot work. You have two different instances of the VCL in your app, one from the exe and one from the DLL. That's one VCL too many.

You can most easily understand this by thinking about what objects are. Objects are both data and code. When you pass an object from exe to DLL you pass the data, but not the code. Delphi objects are not viable cross-language interop types. When you pass your D5 TApplication instance to your XE DLL the XE code interprets it as if it were an XE TApplication. But it is not. The same issue applies for your MDI parent and children. The former is a D5 form, the latter an XE form and so their interactions cannot succeed.

Packages solve this problem by sharing a single instance of the VCL but of course that has the corollary that all packages are built with the same version of Delphi. If you want to use the VCL, that is a hard constraint.

So, if you want some of your forms built with XE, you need to port the entire application.

0
votes

The ONLY alternative to Dave's quite excellent answer is to use sharemem, but I think you will still run into the VCL version problem.