Solved

Forms in DLL's

Posted on 2000-05-05
11
259 Views
Last Modified: 2010-04-04
Hi. I want to create a form using a different version of Delphi from which I'm using to develope the main application. Imagine, for example, I have an application developed in Delphi 4 and I want to develope a single form in Delphi5 in order to use some features that D4 doesn't have.

I have heard that you can turn a form into a DLL and then call that DLL from your program, and it will behave as if the form was really in your program. But I also need my 'DLL form' to use forms in the main program.

Can this be done? How can I do it?

Please explain it to me detailed.

Thanks in advance,

QUIQUE.
0
Comment
Question by:quique
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Author Comment

by:quique
ID: 2780276
I will explain better how I want the forms to comunicate:

Imagine in the main program there is a DataModule. Then I need to use tables defined in that DataModule in the 'DLL form' also!

QUIQUE.
0
 
LVL 1

Expert Comment

by:sxfo
ID: 2780333
This may be more work than it's worth. YOu will need to carry around both the core sets of VCL code. I would imagine that any functionality that is new in D5 would need the base classes of D5 and will not function with the base classes of D4.

Have fun
0
 
LVL 1

Expert Comment

by:msedi
ID: 2780341
Hello quiqui,

yes, there's a possibility to put the form in a dll, but you can't have access to the properties in a normal way. I will explain three methods that could be helpful:

1. Put the form in all DLL and then export a function the shows and creates the form. There you have no access to the forms' properties and function unless you export them explicitly as seperate functions. That obviously not what you want.

2. Another way is to create an ActiveForm. There you have full access to all properties and methods. The problem here is, that the dll has to be registered and you cannot load the dll with the LoadLibrary mechanism. In this case you have to use the COM functinality which is (in your case) rather easy to handle. Keep in mind, that you always have to register you ActiveForm DLL's!!!!

3. The third possibility would be: You create a DLL with an exported functions like the first point. But there the function won't show and create the form, but will create the form and export the pointer to the form. Then in your main application you can cast the pointer to the form and you can use the form like always.

Maybe this helps,
Good luck,
Martin
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:quique
ID: 2781733
Hi, msedi.

I would like you to explain me the third option further.

Please, show me, above all, how I can export the pointer to the form, because I have no idea on how to do it!

Thanks in advance,

QUIQUE.
0
 
LVL 1

Author Comment

by:quique
ID: 2781868
Please, give me a more detailed answer as I ask you in my previous comment.

Thanks,

QUIQUE.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2782456
There are two easier ways:

1. Pass the application object to the DLL, like this:

var
  OldApp : TApplication;

Procedure SetApplication(Appl : TApplication);
begin
  OldApp := Application;
  Application := Appl;
end;

Then just create and show forms as normal.

2. (Easier still)
   Turn on packages by going to Project Options|Packages and checking "Build with runtime packages.

  Do this for both your app and the dll. Build both and away you go!

Cheers,

Raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2782460
Oh, if you pass the application object to the DLL you must set the oldapp back before you destroy the DLL or you will get exceptions.

Cheers,

Raymond.
0
 
LVL 1

Author Comment

by:quique
ID: 2787767
I prefer msedi's solution. I am waiting to his answer.

QUIQUE.
0
 
LVL 1

Expert Comment

by:msedi
ID: 2789304
Hello,

sorry that it took so long. But I was at university and my email forward didn't work. What I mean is, that you can create an abstract class which you use in your main form. For example:

type
  TTest = class(TObject);
 ...
   procedure Beep(); abstract;
  end;


Then you create your DLL and fill this abstract inherited class with your code an export one function that creates the object and returns the pointer to this object

in the dll:

write the class code here

interface
type
  TTest2 = class(TTest)
    procedure Beep(); override;
  end;

implementation
  TTest2.Beep();
  begin
    MessageBeep(MB_OK);
  end;


and create a function that creates and gives the object as result:

function CreateObject () : TTest;
begin
  Result := TTest.Create(nil);
end;


Then use this function in the main form:

....
var
  form : TTest2;

begin
  form := CreateObject();

  form.Beep();
  form.Free();
end;

I don't know exactly whether this works or not, but is almost the same functinality that COM does except that the DLL can be use with almost every programming language for Windows,

PS: If you have any questions, please mail to msedi@freenet.de until my forward works or I will look in this newsgroup. Unfortunately it is not possible to enter two emails in this group.


Good luck, Martin





0
 
LVL 1

Accepted Solution

by:
msedi earned 155 total points
ID: 2789316
Hello,

sorry that it took so long. But I was at university and my email forward didn't work. What I mean is, that you can create an abstract class which you use in your main form. For example:

type
  TTest = class(TObject);
 ...
   procedure Beep(); abstract;
  end;


Then you create your DLL and fill this abstract inherited class with your code an export one function that creates the object and returns the pointer to this object

in the dll:

write the class code here

interface
type
  TTest2 = class(TTest)
    procedure Beep(); override;
  end;

implementation
  TTest2.Beep();
  begin
    MessageBeep(MB_OK);
  end;


and create a function that creates and gives the object as result:

function CreateObject () : TTest;
begin
  Result := TTest.Create(nil);
end;


Then use this function in the main form:

....
var
  form : TTest2;

begin
  form := CreateObject();

  form.Beep();
  form.Free();
end;

I don't know exactly whether this works or not, but is almost the same functinality that COM does except that the DLL can be use with almost every programming language for Windows,

PS: If you have any questions, please mail to msedi@freenet.de until my forward works or I will look in this newsgroup. Unfortunately it is not possible to enter two emails in this group.


Good luck, Martin





0
 
LVL 1

Author Comment

by:quique
ID: 2791826
I have solved it myself. I have created a new type with a procedure of object in order to pass a procedure as argument to a function and it works.

Also, I had to include "Sharemem" in uses list because I was using String as parameters between the DLL and the main program.

Thanks for your support,

QUIQUE.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Find and Replace Stream with 0s 8 72
Delphi and Access based Enumeration 9 78
How to make Sign in, using Clientdataset? 1 33
firemonkey Android Listview Sort items 7 72
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question