Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Pascal/Delphi

Pascal/Delphi Forum for discussing Borland Delphi and Pascal coding techniques, tips and tricks.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-03-2006, 07:12 PM
MrDiaz MrDiaz is offline
Learning Programmer
 
Join Date: Jul 2006
Posts: 65
Rep Power: 9
MrDiaz is on a distinguished road
Default How do you make forms in a dll

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:

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

Code:
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:

Code:
uses
 SysUtils,
 Classes,
 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:

Code:
procedure ShowDllForm;stdcall;
begin
 Form2 :=TForm2.Create(nil);
 Form2.Show;
end;
And number two:
Code:
function ShowDllFormModal:integer;stdcall;
begin
 Form2 :=TForm2.Create(nil);
 Result := Form2.ShowModal;
end;
Now we need to set up the following code to export our procedures into our application.

Code:
Exports
  ShowDllForm,
  ShowDllFormModal;
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

Code:
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:

Code:
ShowForm
Button Showmodal:

Code:
ShowFormModal
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VB 6.0: Tutorial, How to Make Glass2K!! TcM VB Tutorials 12 09-28-2008 12:53 PM
VB 6.0: Tutorial, How to make a GIF in your application TcM VB Tutorials 17 07-01-2008 04:26 PM
How to make and use a library twitch C Tutorials 0 06-13-2007 05:32 AM
How to make Dumplings ahsan16 The Lounge 2 01-11-2007 11:55 PM


All times are GMT -5. The time now is 02:35 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads