?
Solved

using forms in dll's

Posted on 1999-07-09
10
Medium Priority
?
136 Views
Last Modified: 2012-05-04
Hi,
I want to create a program, which is expandable using dll's.
My       Q1:      How can I put a form in a DLL?
      Q2:      How do I make the form visible?

I thought I had the answer by just exporting the form's object type. But, when I import, using getprocaddr, the object and call the form.create. I receive a Exception.

Example of my code:

Var Form1:TForm

 Handle := LoadLibrary('LIBFORMTEST.DLL');
  if Handle <> 0 then
  begin
    Form1 := GetProcAddress(Handle, 'TForm1');
    if @Form1 <> nil then
    begin
      Form1.Create(nil);
      Form1.Show;
    end;
  end;

The TForm1 is the exported object type in the DLL.

Anyone has any examples about forms in a dll, or anyone can tell me how to make this work?


Greetz.
  Avataris      
0
Comment
Question by:Avataris
[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
10 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1387359
I could answer this, but Epsylon got a nice demo, so wait for Epsylons demo
0
 
LVL 2

Expert Comment

by:kotik
ID: 1387360
You can put such a function into your DLL:

function CreateForm : TForm;
begin
  Result := TForm.Create(nil);
end;

And call that func from your application as:

Var
  Form1:TForm
  Func : Pointer;

 Handle := LoadLibrary('LIBFORMTEST.DLL');
  if Handle <> 0 then
  begin
    Func := GetProcAddress(Handle, 'CreateForm');
    if @Func <> nil then
    begin
      Form1 := Func;
    end;
  end

I don't know if it will work, but you can try...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387361
Yes, I've got I nice demo. Thanks Zif for refering to me.

Drop your email address here and I'll send it to you.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 1387362
Epsylon,

When you read this, can you send me that demo, or post the code for it here, or something.  I'd be interested to see how you do it.

Stu.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1387363
mmm, still no notifactions... well, I've to check all these messages! Damn.

Stu, can you send an example as well?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387364
Of course, Stu, your have sent me something a few week ago so it seems fair to me to send you something back. It's even about the same subject.   :o)

But you have to wait a few hours because I only have it at home.

Eps.
0
 
LVL 15

Accepted Solution

by:
simonet earned 300 total points
ID: 1387365
Avataris,

You do not call the creator of the form in the DLL. Instead, the correct way to do it is to create a global procedure (a procedure that doesn't belong to any class) in the DLL and export it. This procedure will be responsible for creating the form in the DLL.

Therefore, the code in the DLL would look like:

procedure DisplayForm1; export;
begin
 with TForm1.create(nil) do
   show;
end;

Then just export the DisplayForm1 procedure from the DLL. Optionally this procedure can receive the handle of the main application which must be used as the Ownwer of the form.

Your TForm1 class must be set to destroy itself on the OnClose event.

In your application, you can simply call DisplayForm1 using GetProcAddress or dynamically linking it to your application:

procedure DisplayForm1; external 'LIBFORMTEST.DLL';

Please let me know if you have questions implementing that on your application.

Yours,

Alex
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387366
Avataris, do you want that demo or not?
0
 

Author Comment

by:Avataris
ID: 1387367
I'm sorry.. Have been busy lately....;(
Apologies.

Well, I've tried your suggestion, It works fine THX!..
Not as the way I wanted to but, this works oke for me too...

Have you placed your demo somewhere?

Maybe there are other users with doing the same project as I.

I want to create a modular wave studio. So that it can be used as
- A modular Synthesizer
- A Sampler
- And last but not least a Vocoder!

Greetz..
 Avataris
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1387368
No I have not.
0

Featured Post

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!

Question has a verified solution.

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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 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