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:
Now let's move ahead and create our resource DLL.Code:Action := caFree;
- 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
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.Code:Unit2 in 'Unit2.pas' {Form2};
This is how your code should look like in the uses:
Once you have that you can click project -> build and that will generate the DLL for you.Code:uses SysUtils, Classes, Unit2 in 'Unit2.pas' {Form2};
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:
And number two:Code:procedure ShowDllForm;stdcall; begin Form2 :=TForm2.Create(nil); Form2.Show; end;
Now we need to set up the following code to export our procedures into our application.Code:function ShowDllFormModal:integer;stdcall; begin Form2 :=TForm2.Create(nil); Result := Form2.ShowModal; end;
After all that has been created, build the project again.Code:Exports ShowDllForm, ShowDllFormModal;
Click Project -> Build
Now let's go into our actual application. You need to add the following code just above Var
In the external you must set up the name of your dll, in the one I created the name is Project2.dll.Code:procedure ShowForm;stdcall;external 'Project2.dll' name 'ShowDllForm'; function ShowFormModal:integer;stdcall;external 'Project2.dll' name 'ShowDllFormModal';
Now let's create 2 buttons to call this procedures.
Button Show:
Button Showmodal:Code:ShowForm
After that we go back to our dll project and we build it again.Code:ShowFormModal
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!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks