Solved

Forms in DLL's

Posted on 2000-05-05
11
258 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
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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
Communication Between RC4 Delphi <-> PHP 3 123
error 1.1 400 Bad request idhttp delphi 18 143
How to renew a Delphi rad-studio licence? 5 69
Delphi Yen format 3 45
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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