delphi exe and dll without build with runtime packages

▼魔方 西西 提交于 2019-12-19 04:55:10

问题


For my last project i was using many frames in my delphi application ,so i dicided to create dlls and put them inside the dlls(ALL created in Delphi)

i have gone through many websites and came up with the code that works but for that example i have to compile both apps and dlls with build with runtime packages which means i have to distribute the bpls also. and if dont check build with runtime packages error is coming

this is the code i found

in exe

procedure TForm1.Button1Click(Sender: TObject);
type
TGetTheFrame =Function( Owner: TComponent; TheParent: TWinControl ): TFrame; stdcall ;
 var
  GetTheFrame : TGetTheFrame;
begin
try
   GetTheFrame(application,TabSheet1).Free ;
except
end;
frm := GetTheFrame(application,TabSheet1) ;
dllHandle := LoadLibrary('project1.dll') ;
   if dllHandle <> 0 then
   begin
     GetTheFrame := GetProcAddress(dllHandle, 'GetTheFrame') ;
  frm := GetTheFrame(application,TabSheet1)   //call the function
    {   ShowMessage('error function not found') ;
     FreeLibrary(dllHandle) ; }
   end
   else
   begin
     ShowMessage('xxxx.dll not found / not loaded') ;
   end

in dll

Function  GetTheFrame( Owner: TComponent; TheParent: TWinControl ): TFrame; stdcall;
Begin
 Result := TFrame2.Create( Owner );

 Result.Parent := TheParent;
End;

thats all but i want this code to work without runtime packages


回答1:


Too bad. That code won't work without run-time packages. (And with run-time packages, you should use LoadPackage instead of LoadLibrary.)

Without packages, each module of your program (the EXE and each DLL) has its own copy of the definition of all the standard classes, including TFrame, TWinControl, and even TObject. A TWinControl class from the EXE doesn't look like a TWinControl to the DLL.

Since you're sharing classes between modules, you need to make sure they all have the same definitions of those classes, and run-time packages is how you do that.

If you really won't use run-time packages, then you need to change the interface of your DLL so it doesn't share any Delphi object types. Instead of the TWinControl parent, pass the control's Handle property, or any other HWnd value to serve as the parent window. The DLL code will not be able to assume that there is a Delphi object for the parent anymore, and the EXE will not be able to assume that the control it receives is a Delphi object; they will be restricted to using the Windows API to manipulate window handles and send messages.



来源:https://stackoverflow.com/questions/3987548/delphi-exe-and-dll-without-build-with-runtime-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!