Vib*_*nRC 0 delphi dll runtime bpl frame
对于我的上一个项目,我在delphi应用程序中使用了很多帧,所以我决定创建dll并将它们放在dll中(所有在Delphi中创建)
我已经浏览了很多网站,并提出了有效的代码,但对于该示例,我必须使用运行时包编译这两个应用程序和dll,这意味着我还必须分发bpls.如果不检查构建与运行时包错误即将到来
这是我发现的代码
在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
Run Code Online (Sandbox Code Playgroud)
在DLL中
Function GetTheFrame( Owner: TComponent; TheParent: TWinControl ): TFrame; stdcall;
Begin
Result := TFrame2.Create( Owner );
Result.Parent := TheParent;
End;
Run Code Online (Sandbox Code Playgroud)
多数民众赞成我只希望这个代码在没有运行时包的情况下工作
太糟糕了.没有运行时包,该代码将无法运行.(对于运行时包,您应该使用LoadPackage而不是LoadLibrary.)
如果没有包,程序的每个模块(EXE和每个DLL)都有自己的所有标准类的定义副本,包括TFrame,TWinControl甚至TObject.一个TWinControl从EXE类看起来并不像一个TWinControl到DLL.
由于您在模块之间共享类,因此您需要确保它们都具有相同的类定义,并且运行时包就是您这样做的方式.
如果您真的不使用运行时包,那么您需要更改DLL的接口,以便它不共享任何Delphi对象类型.而不是TWinControl父代,传递控件的Handle属性或任何其他HWnd值作为父窗口.该DLL的代码将不能够假定有一个Delphi对象父了,而EXE将不能够假定它接收到的控制是一个Delphi对象; 他们将被限制使用Windows API来操作窗口句柄和发送消息.