October 25th, 2004, 03:39 AM
Add a Form into a DLL
How can add a form after it was designed in Delphi into a DLL file to have a separate DLL file for each screen in my application?
October 26th, 2004, 11:27 AM
Simply adding a form to your DLL project. In your DLL you have to runtime create the form in the initialization code, or you can write a proc/func for creating this form and then you have to export it to your application.
If you have an MDI application, and you want that your external form works as a child, you have to pass to your DLL the Application.handle value and the MainForm.handle value if MainForm is the name of your parent form in the application.
In the DLL you have to assign:
Application.handle := PassedAppHandle;
yourDLLForm := TyourDLLForm.CreateParented(PassedFormHandle)
Your form will appear as an MDI child, but DON'T SET YOUR DLLFORM FORMSTYLE PROPERTY TO fsMDIChild
October 28th, 2004, 08:13 AM
thanks for your reply...
I am lost.....
can you please explain in step-by-step with a simple example.
November 2nd, 2004, 01:47 PM
November 14th, 2004, 04:56 PM
Originally Posted by jrahma
I AM STILL WAITING FOR HELP...
I also wanted to ask if there is any other (better) way to separate each form when distributing the application?
November 16th, 2004, 03:46 AM
the thread was closed by mistake....
you can post a reply now...
November 17th, 2004, 05:03 AM
Forms in DLL
Sorry, I had very hard problems with my computer last weeks.
I apologize fro this.
Here, I send you an example of loading forms in an application.
When you call the DLL you have to pass to the library the Application.Handle value of your host application, and the Host Application Main Form handle value.
For example you can write something like this (in you application)
TProc = function(hApp, hMainForm):THandle;stdcall;
hLib : THandle;
ShowF : TProc;
hLib := LoadLibrary('c:\....\myLibrary.dll);
if hLib <> 0 then
//Getting ShowForm proc address
ProcAddr := GetProcAddress(h,'ShowForm');
if Assigned(ProcAddr) then
ShowF := ProcAddr;
Result := ShowF(Application.handle,MyMainForm.handle);
In your DLL you have to put something like this:
function ShowForm(hApp, hMainForm):THandle;sdtcall
function ShowForm(hApp, hMainForm):THandle;
Application.handle := hApp;
MyDLLForm := TMyDLLForm.Create(Appplication);
MyDLLForm.parentwindow := hMainForm;
result := MyDLLForm.handle;
OldDLLAppHandle := Application.handle;
Application.handle := OldDLLAppHandle;
And then you have to export your Dll ShowForm procedure
November 17th, 2004, 09:45 AM
Thank you very much....
But in the case I will have to recode everthing again including all buttons, menus, textbox, etc..
is these any way to design the form in delphi IDE and then compile it (export it) as a DLL?
November 18th, 2004, 03:26 AM
Hi,that's not a problem.....you only have to create a DLL project, and then you can create a form in the DLL project with File|New|Form. You can simply design ad write code for your form as with exe applications. Delphi will compile the form in the dll normaly as if you have a normal application project.
But, to debug your project you have to use a host application, that calls your dll. To set this parameters, chose Run|Parameters in the delphi IDE, ans set the Host Application field to your main app