Avatar of hidrau
hidrau
Flag for Brazil asked on

How to call a form that is in a DLL from an application?

Hello guys,

Today my delphi application is 120 mb of exe, I think it is very big exe file.
I would like to split many of forms to DLLs, so that I can reduce the exe file.

I have some doubts:

how to call a form from my exe application?
is the same way to call a form from a DLL too?

Do you have any example to show me how to?

regards
Alexandre
Delphi

Avatar of undefined
Last Comment
hidrau

8/22/2022 - Mon
Geert G

a big exe

or lots of smaller dll's and a smaller exe, probably totalling to more than 120mb
and a bit of dll-hell

in essence, deploying 1 exe is way simpler than deploying multiple files

have you tried looking what's causing the large size ?
allowing multiple themes or skins is usually 1 such item, which doesn't add to the functionality
hidrau

ASKER
I have 259 forms in my project :(
SOLUTION
Geert G

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hidrau

ASKER
I see. Thanks a lot for some ideas,

But the solution to me at this moment is DLL, split my application into some DLL files.

I know how to create a DLL, but my problem is how to call a form that is in a DLL from my application.

If you can do a simple example so that I can study it and go ahead, it would be very interesting to me.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Sinisa Vuk

Look at my old answer here on EE to similar question...
hidrau

ASKER
Hello Sinisa,

It is really very simple, I made the example and worked.

I followed this : http://www.delphi-central.com/formdll.aspx

But I need to load my form Explicit and I didn't have success :(

I also followed this link:

http://www.drbob42.com/delphi/headconv.htm

this code in my application where I call the DLL that has the form:

procedure Tform1.Button5Click(sender: Tobject);
Var
  TcadCliente : procedure; 
  Handle : THandle;
Begin 
  Handle := LoadLibrary('DllFuncoes.dll');
  If handle <> 0 Then 
  Begin 
    Tcadcliente := GetProcAddress(Handle, 'ChamaCadCliente');
    FreeLibrary(Handle)
  End 
End

Open in new window


What is wrong? The form doesn't appear on the screen.

If I call the form Implicit, it works fine :(  - The first example is an implicit method.

Thanks
Geert G

call FreeLibrary when you no longer need to call the dll
Your Tcadcliente address will only be valid until FreeLibrary
The address  TcadCliente will call the dll ...

load the dll's at the beginning of the program or when you need it for the first time
the first can lead to longer start time, the latter to some coding overhead
unload the used library before closing the application, usually in mainform destroy or finalization

it might be best to start with ModalDialogs
like this:

procedure ShowUserInfo(List: TStrings);
var frm: TfrmUserinfo;
begin
  frm := TfrmUserInfo.Create(nil);
  try
    frm.LabelLastName.Caption := List.Values['LAST_NAME'];
    frm.LabelFirstName.Caption := List.Values['LAST_NAME'];
    // etc ... 
    frm.ShowModal;
  finally
    frm.Free;
  end;
end;

Open in new window


btw above sample also implements expicitly creating and freeing a form
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Sinisa Vuk

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
hidrau

ASKER
Thanks a lot
hidrau

ASKER
Sinisa Vuk,

I am getting an error :(

It is strange because in Delphi 7 I don't receive the error, only with Delpi XE7.

The application compiled perfect, when I call the application and click on the button to call the form that is in my DLL workes fine so far, the error happens when I close the form.

Something that also forgot?

please, download my application study

http://www.teachmenow.com.br/instalador/font.rar

thanks
hidrau

ASKER
After breathing a little bit :) I think I found the problem.

In my dll I wasn't distroying the form with free, I was using release

it was:
form := Tform1.create(nil)
Try
   form.showmodal
Finally
  form.release
  form := nil
End

it worked fine when I made the changes

form := Tform1.create(nil)
Try
   form.showmodal
Finally
  form.free
  form := nil
End

If you can take a look at my example, you gonna see
Your help has saved me hundreds of hours of internet surfing.
fblack61
Geert G

Release is to be called in an event handler
like inside an onclick

it add's a message on the queue of the form : WM_RELEASE
and waits to processs it

in a finally, there is no point in using release

setting form := nil depends if you use local variables or not
my sample in ShowUserInfo doesn't require a frm:= nil as it is a local procedure

if you have global or variables in the implementation section, that's when you might have to use nil
that's usually when you only want a single instance of a form
hidrau

ASKER
thanks for all the comments