?
Solved

Forms in DLL's

Posted on 2000-05-05
11
Medium Priority
?
263 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
Technology Partners: 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 465 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

762 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