Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

How do you make forms in a dll

  • Please log in to reply
No replies to this topic

#1 MrDiaz


    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 03 July 2006 - 03:12 PM

Well I figured this out. Let me guide you through the process, it is very simple but it might be tricky so follow me lead and don't get lost! :)

First we want to create a new application. The mother application.

- Click New -> Application

Now that you have your application created, you can create the form you would like to include in your DLL. Don't worry, it will not be compiled within the application.

- Click New -> Form

For your application to not consume more memory we need to destroy the form when we close it. So we just add to the onClose event of the form the following code:

Action := caFree;

Now let's move ahead and create our resource DLL.

- Click New -> DLL Wizard or whatever it shows for you.

In the uses, you have have to add the unit you want to include in your resource (The fom you want to use)

In this case the unit we created is named Unit2, so we write just below the uses

Unit2 in 'Unit2.pas' {Form2};

Note that Form2 is the name of the form you created, if your form's name is another, just rename the code above. It will work the same way.

This is how your code should look like in the uses:

 Unit2 in 'Unit2.pas' {Form2};

Once you have that you can click project -> build and that will generate the DLL for you.

Now let's create two procedures, one to show the form and another one to show the form modal. You can add as many procedure as you want, I will just add 2 to give you an idea.

Let's create procedure one:

procedure ShowDllForm;stdcall;
 Form2 :=TForm2.Create(nil);

And number two:
function ShowDllFormModal:integer;stdcall;
 Form2 :=TForm2.Create(nil);
 Result := Form2.ShowModal;

Now we need to set up the following code to export our procedures into our application.


After all that has been created, build the project again.

Click Project -> Build

Now let's go into our actual application. You need to add the following code just above Var

procedure ShowForm;stdcall;external 'Project2.dll' name 'ShowDllForm';
 function ShowFormModal:integer;stdcall;external 'Project2.dll' name 'ShowDllFormModal';

In the external you must set up the name of your dll, in the one I created the name is Project2.dll.

Now let's create 2 buttons to call this procedures.

Button Show:


Button Showmodal:


After that we go back to our dll project and we build it again.

Click Project -> Build

And that's it! You have created a resource dll. This saves resources and it reduces your application memory usage and file size too.

Happy Coding!
  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download