如何使用Delphi Dll而不启用使用运行时包的Build [英] How to use Delphi Dlls without enabling Build with runtime packages

查看:295
本文介绍了如何使用Delphi Dll而不启用使用运行时包的Build的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始了一个有这么多表单,框架和额外控件的项目,所以我的应用程序正在膨胀,我在我的项目中使用3个exe(所有这些都在Delphi 2009中),这些应用程序也共享相同的框架和表单。所以我使用dll来共享这些表单。



但是一个问题来了说不同的Tfont错误。所以我在网上补充说,选择|使用运行时软件包构建然后每件事情开始正常工作



但是当我检查窗口Taskmanager | memusage它是〜21 500 kb(21.5 mb)(但mem使用只有2000 kb没有Build与运行时包,也通过将其添加到所有3个exe项目中手动添加框架),我的编译器也很慢,启用Build with运行时程序包



现在我必须使用 3 exes + delphi bpl运行时包+ dlls 分配项目

但是我想知道memusage如何增加,我只想摧毁 3 exes + dlls (正常的delphi exes是如何传播的)我甚至使用内存管理器,但没有工作



如何解决这个问题



这是我使用的代码



in 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

 使用
Windows,
消息,
SysUtils,
类,
表单,StdCtrls,控件,

Unit2 in'Unit2.pas'{Frame2:TFrame};

{$ R * .res}

函数GetTheFrame(Owner:TComponent; TheParent:TWinControl):TFrame;标准
开始
结果:= TFrame2.Create(Owner);

Result.Parent:= TheParent;
结束;


导出gettheframe;

begin
end。

最后如何使用运行时pakages em>



更多的内存问题只是告诉我如何在没有buildwithruntime软件包的情况下创建这样一个应用程序

解决方案

1)我认为它的自然,特别是如果有很多的对象/图像等,如果你把一些图像/表单等移动到dll作为资源。然后在需要的时候调用它,如果没有,请将其释放。



2)尝试也检查内存泄漏。我以前有同样的问题,当我的程序启动内存使用越来越大。尝试使用FastMM4。



3)排除一些未使用的bpls。因为它创建运行时,即使你不使用它。例如InterBaseDriver; DBXMySQLDriver; dbexpress; dbxcds; VirtualTreesD12等我没有使用它,所以不要放过它。尝试知道你所使用的所有单位,它们属于什么样的bpl。


Recently i started a project with so many forms , frames and extra controls, so my application was swelling up and i am using 3 exes in my projects(all made in Delphi 2009) and these applications are also sharing same frames and forms. so i used dlls to share these forms.

but a problem came saying different Tfont error. so i refferd online and came with the answer saying to select | Build with runtime packages .then every thing started to work perfectly

but when i checked the windows Taskmanager | memusage it is ~ 21 500 kb (21.5 mb).( but mem usage is only 2000 kb without Build with runtime packages , also includimg frames manually by adding it inside the all 3 exe projects)and my compiler also works slow with enabling Build with runtime packages

and now i have to distribute the project with 3 exes + delphi bpl runtime packages + dlls

but i want to know how memusage increased and i only want to destribute 3 exes + dlls (just how normal delphi exes are destributed)i have even used memory managers but not worked

how to over come this problem

this is the code i used

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

uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Forms,StdCtrls, Controls,

  Unit2 in 'Unit2.pas' {Frame2: TFrame};

{$R *.res}

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

 Result.Parent := TheParent;
End;


exports gettheframe;

begin
end.

and at last how to do all these without build with runtime pakages

more than memory problems just tell me how to create such an application without buildwithruntime packages

解决方案

1) i think its natural, specially if there are alot of object/images etc. how about if you move some images/forms etc to dll as resource. then call it when needed and freed if not.

2) try also checking memory leaks. i have same problem before, when my program starts the memory usage is getting bigger and bigger. try to use FastMM4.

3) exclude some bpls that is not being use. because it created runtime even if you do not use it. example "InterBaseDriver;DBXMySQLDriver;dbexpress;dbxcds;VirtualTreesD12 etc.." i did not use it, so im gont to excluse it. try to know all the units u used to what bpl they belong.

这篇关于如何使用Delphi Dll而不启用使用运行时包的Build的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆