• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 185
  • Last Modified:

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
0
hidrau
Asked:
hidrau
  • 7
  • 4
  • 2
2 Solutions
 
Geert GOracle dbaCommented:
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
0
 
hidrauAuthor Commented:
I have 259 forms in my project :(
0
 
Geert GOracle dbaCommented:
any items in common amongst those forms or a group of forms ?

usually it's possible to use visual form inheritance to bundle common items
descending forms can have very little code to add / alter functionality

another possibity is to use frames
for same pieces of functionality spread across different forms
1
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
hidrauAuthor Commented:
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.
0
 
Sinisa VukCommented:
Look at my old answer here on EE to similar question...
1
 
hidrauAuthor Commented:
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
0
 
Geert GOracle dbaCommented:
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
1
 
Sinisa VukCommented:
you forget to call your form before FreeLibrary:
procedure Tform1.Button5Click(sender: Tobject);
Var
  TcadCliente : procedure; 
  Handle : THandle;
Begin 
  Handle := LoadLibrary('DllFuncoes.dll');
  If handle <> 0 Then 
  Begin 
    Tcadcliente := GetProcAddress(Handle, 'ChamaCadCliente');
    if Assigned(Tcadcliente) then
       Tcadcliente();
    FreeLibrary(Handle)
  End 
End

Open in new window

1
 
hidrauAuthor Commented:
Thanks a lot
0
 
hidrauAuthor Commented:
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
0
 
hidrauAuthor Commented:
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
0
 
Geert GOracle dbaCommented:
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
1
 
hidrauAuthor Commented:
thanks for all the comments
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now