delphi exe和dll没有使用运行时包构建 [英] delphi exe and dll without build with runtime packages
问题描述
我已经经历了许多网站,并提出了代码,但为了这个例子,我必须编译两个应用程序和dll与构建与运行时包,这意味着我也必须分发bpls。如果不检查使用运行时包的构建错误即将到来
这是我发现的代码
在exe
procedure TForm1.Button1Click(Sender:TObject);
type
TGetTheFrame = Function(Owner:TComponent; TheParent:TWinControl):TFrame;标准
var
GetTheFrame:TGetTheFrame;
begin
try
GetTheFrame(application,TabSheet1).Free;
除
结束;
frm:= GetTheFrame(application,TabSheet1);
dllHandle:= LoadLibrary('project1.dll');
如果dllHandle<> 0然后
begin
GetTheFrame:= GetProcAddress(dllHandle,'GetTheFrame');
frm:= GetTheFrame(application,TabSheet1)//调用函数
{ShowMessage('error function not found');
FreeLibrary(dllHandle); }
end
else
begin
ShowMessage('xxxx.dll not found / not loaded');
end
在dll
函数GetTheFrame(Owner:TComponent; TheParent:TWinControl):TFrame;标准
开始
结果:= TFrame2.Create(Owner);
Result.Parent:= TheParent;
结束;
只有我希望此代码无需运行时包即可工作
div class =h2_lin>解决方案
太糟糕了。该代码将无法运行时包。 (和 运行时包,您应该使用 LoadPackage
而不是 LoadLibrary
。)
没有包,程序的每个模块(EXE和每个DLL)都有自己的所有标准类定义的副本,包括 TFrame
, TWinControl
,甚至 TObject
。来自EXE的 TWinControl
类看起来不像DLL的 TWinControl
。
由于您在模块之间共享类,因此您需要确保它们都具有与这些类相同的定义,并且运行时包是如何实现的。
如果您真的不使用运行时软件包,那么您需要更改DLL的界面,因此不会共享任何Delphi对象类型。传递控件的句柄
属性,或任何其他 HWnd code>值作为父窗口。 DLL代码将无法假定父代有一个Delphi对象,EXE将无法假定它接收到的控件是一个Delphi对象;他们将被限制为使用Windows API来操纵窗口句柄和发送消息。
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
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.
这篇关于delphi exe和dll没有使用运行时包构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!