#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11

    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?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    14
    Rep Power
    0
    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

    Bye bye
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11
    hi,


    thanks for your reply...



    but....


    I am lost.....



    can you please explain in step-by-step with a simple example.




    many Thanks.....
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11
    can you please help....
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11
    Originally Posted by jrahma
    can you please help....

    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?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11
    sorry,



    the thread was closed by mistake....



    you can post a reply now...
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    14
    Rep Power
    0

    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)

    function CallMyDLLForm:THandle;;
    type
    TProc = function(hApp, hMainForm):THandle;stdcall;
    var
    hLib : THandle;
    ProcAddr: Pointer;
    ShowF : TProc;
    begin
    //Loading Library
    hLib := LoadLibrary('c:\....\myLibrary.dll);
    if hLib <> 0 then
    beign
    //Getting ShowForm proc address
    ProcAddr := GetProcAddress(h,'ShowForm');
    if Assigned(ProcAddr) then
    begin
    ShowF := ProcAddr;
    Result := ShowF(Application.handle,MyMainForm.handle);
    end;
    end;
    end;



    In your DLL you have to put something like this:

    unit LibProcs

    interface
    uses......

    function ShowForm(hApp, hMainForm):THandle;sdtcall

    var
    OldDLLAppHandle: THandle;

    implementation


    function ShowForm(hApp, hMainForm):THandle;
    begin
    Application.handle := hApp;
    MyDLLForm := TMyDLLForm.Create(Appplication);
    MyDLLForm.parentwindow := hMainForm;
    result := MyDLLForm.handle;
    MyDLLForm.Show;
    end;

    initialization
    OldDLLAppHandle := Application.handle;


    finalization
    Application.handle := OldDLLAppHandle;


    And then you have to export your Dll ShowForm procedure

    That's all!

    Enjoy...goodbye!!!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    52
    Rep Power
    11
    Hi,

    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?


    many Thanks,
    Jassim Rahma
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    14
    Rep Power
    0
    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

    Bye

IMN logo majestic logo threadwatch logo seochat tools logo