如何在不启用使用运行时包构建的情况下使用 Delphi Dll

发布于 2024-09-28 20:20:19 字数 1790 浏览 1 评论 0原文

最近我开始了一个包含如此多表单、框架和额外控件的项目,因此我的应用程序不断膨胀,我在项目中使用了 3 个 exe(全部由 Delphi 2009 制作),并且这些应用程序也共享相同的框架和表单。所以我使用 dll 来共享这些表单。

但是出现了一个问题,提示不同的 Tfont 错误。所以我在网上转诊,得到的答案是选择 |使用运行时包构建然后一切都开始完美工作

但是当我检查 Windows Taskmanager | memusage 大约为 21 500 kb (21.5 mb)。(但在没有使用运行时包构建的情况下,mem 使用量仅为 2000 kb,还包括通过将其添加到所有 3 个 exe 项目中手动添加帧)并且我的编译器在启用 Build with 时运行速度也很慢运行时包

,现在我必须使用3个exes + delphi bpl运行时包+dll分发项目,

但我想知道memusage是如何增加的,我只想分发3个exes+dll强>(正常的delphi exe是如何分布的)我什至使用了内存管理器,但没有工作

如何解决这个问题

使用的代码

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

这是我在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.

最后如何做所有这些不使用运行时包进行构建

不仅仅是内存问题,只是告诉我如何在不使用 buildwithruntime 包的情况下创建这样的应用程序

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

溺ぐ爱和你が 2024-10-05 20:20:19

1)我认为这是自然的,特别是如果有很多对象/图像等。如果你将一些图像/表单等移动到dll作为资源怎么样?然后在需要时调用它,如果不需要则释放它。

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

3) 排除一些未使用的bpls。因为即使您不使用它,它也会创建运行时。例如“InterBaseDriver;DBXMySQLDriver;dbexpress;dbxcds;VirtualTreesD12 等..”我没有使用它,所以我不会排除它。尝试了解您使用过的所有单位以及它们所属的 bpl。

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.

梦魇绽荼蘼 2024-10-05 20:20:19

不要对框架使用 dll,而应使用 bpl。

因此,创建一个新包,在其中添加框架的代码。在您的应用程序中,将该单元与框架一起使用并调用 TFrame2.Create(Self);,就像您没有 dll 时通常所做的那样。

在可执行文件中:

procedure TForm1.Button1Click(Sender: TObject);
var
  MyFrame: TFrame2;
begin
  MyFrame := TFrame2.Create(Tabsheet1);
  MyFrame.Parent := Tabsheet1;
end;

Do not use dll's for your frames but bpl's.

So create a new package, add the code for your frame in it. In your application, use the unit with the frame and call TFrame2.Create(Self); like you would normally do if you didn't have dll's.

In exe:

procedure TForm1.Button1Click(Sender: TObject);
var
  MyFrame: TFrame2;
begin
  MyFrame := TFrame2.Create(Tabsheet1);
  MyFrame.Parent := Tabsheet1;
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文