How to use Delphi Dlls without enabling Build with

2019-02-11 08:34发布

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

2条回答
Lonely孤独者°
2楼-- · 2019-02-11 09:02

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;
查看更多
冷血范
3楼-- · 2019-02-11 09:21

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.

查看更多
登录 后发表回答