Solved

Forms in DLL's

Posted on 2000-05-05
11
257 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TVirtualStringTree  search using TEdit 7 121
How to fill array with TArray.Create? 14 90
How to renew a Delphi rad-studio licence? 5 65
Multiple image collision 13 75
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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