Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Up to 400 points for a great solution

Posted on 1999-06-30
19
Medium Priority
?
271 Views
Last Modified: 2013-11-18
Hi experts, please read the question carefully. Post comments on this question. I will leave it open for about 5 days and then I will award up to 400 points (that's all I have) depending on the results. Maybe more than one person gets points.

Ok, what do I want?

I am writing an application with plugin support. The idea is that the application looks in a specific directory to look for available plugins and build a visual list of them with the name and an icon. The user can select one and in a certain area on the form the interface of the selected plugin pops up. Such an interface can have buttons, editboxes, listviews, etc. I must be able to design the interface of a plugin in Delphi. Coded designs are unacceptable.
The plugins should not be registered to the system so ActiveX, COM, DCOM, OLE won't do because they are registered, right?

THE MAIN QUESTION IS:
How can I implement a construction of 'merging' a form of an external module (like a DLL) into the main application.

What I have done so far is writing DLL's with a form. On this form I can design the interface. In the main application I call a function in the DLL that creates the form and automatically docks it on a panel on the main apps form. This works except that the controls on the DLL-form are not visible until I undock the DLL-form with my mouse. Then they become visible.



Here is the DLL code (it's just for testing):

---------------------------------------------------------------------
library DLLProject;

uses
  SysUtils,
  Classes,
  Forms,
  ExtCtrls,
  DLLUnit in 'DLLUnit.pas' {DLLForm};

function GetForm: TDLLForm;
begin
  DLLForm := TDLLForm.Create(nil);
  Result := DLLForm;
end;

exports
  GetForm index 1;

begin
end.
---------------------------------------------------------------------



And here the main app:

---------------------------------------------------------------------
function GetForm: TForm; external 'DLLProject.dll';

var
  Form1: TForm1;
  DLLForm: TForm;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DLLForm := GetForm;
  DLLForm.ManualDock(Panel1);
end;
---------------------------------------------------------------------


This was my first approach but fails. Other great ideas are welcome of course as long as it works ok.

Jimmy.
0
Comment
Question by:JimmyC
[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
  • 6
  • 5
  • 3
  • +3
19 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1385373
Have you tried this one:

function GetForm (parentHandle: hwnd) : TDLLForm;
begin
  DLLForm := TDLLForm.CreateParented(parentHandle);
  Result := DLLForm;
end;

  DLLForm := GetForm(Panel1.handle);


or this one:

  DLLForm := GetForm;
  DLLForm.Parent := Panel1;

Furthermore I would set the borderStyle to none. Looks better for such parented windows, I think.

Regards, Madshi.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385374
Using the code below enables you to decide at runtime where you want the form inserted:


function GetForm(parent: TWinControl): TDLLForm;
begin
  DLLForm := TDLLForm.CreateParented(parent.Handle);
  Result := DLLForm;
end;


procedure TForm1.Button1Click(Sender: TObject);
var hostcontrol: TWinControl;
begin
  hostcontrol := Panel1; // can be Form1 too or another panel
  DLLForm := GetForm(hostcontrol);
  DLLForm.BorderStyle := bsNone;
  DLLForm.Left := 1;
  DLLForm.Top := 1;
  hostcontrol.InsertControl(DLLForm); // you can't use the parent property
end;

Regards,

Epsylon.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385375
Hi Eps, why can't you use the parent property?
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 13

Expert Comment

by:Epsylon
ID: 1385376
Changing the parent property internally does a RemoveControl and a InsertControl. The RemoveControl won't work.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1385377
Listening...
0
 

Expert Comment

by:PROGRAMMING030999
ID: 1385378
Hi,
it could be possible to insert such a DLL in VC++, for
example in a CWnd.

I give 50 Extra Points.

Michael

0
 

Author Comment

by:JimmyC
ID: 1385379
Madshi/Epsylon, I have tried your examples and they work pretty good.
But when I use a ScrollBox that is not big enough to show the DLLForm at once the scrollbar acts weird. So I think something else needs to be done. But what?

With a 'local' form inserted in the scrollbox it works ok. With the DLLForm it doesn't. So could it be something with the InsertControl and parent thing?

Jimmy.
0
 

Author Comment

by:JimmyC
ID: 1385380
PROGRAMMING, I think you can but I don't know exactly how to use DLL's in VC++.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1385381
I think the main difference between a local form and a DLL form is that the Application object is different. Both the application and the DLL have its own Application object. There are two ways around this problem:

(1) Look at Runtime packages. Hmm. I never worked with this stuff. So I tell you what I know about it. Perhaps the other experts can correct me...  :-)
Runtime packages are almost DLLs, but with some Delphi-specific extensions. AFAIK you can link them in a way to the exe, so that both the exe and the package use the same Appliaction object.
(2) Use something like this in one of your DLLs units:

var dllAppObj : TApplication;
procedure ChangeApplication(exesAppObj: TApplication);
begin
  dllAppObj:=Application;
  Application:=exesAppObj;
end;

initialization
finalization
  Application:=dllAppObj;
end.

Of course you must then export this function and call it from the exe after you loaded the library.

I hope the code works. I once did something like this and it worked quite funny. But I'm not sure if it was EXACTLY this way...

Regards, Madshi.
0
 
LVL 2

Expert Comment

by:333
ID: 1385382
hi,
try this:

in your DLL project:
function GetForm(AppHandle: THandle; AppName: ShortString): TDLLForm;
begin
  Application.Handle:=AppHandle;
  ApplicationName:=AppName;
  DLLForm := TDLLForm.Create(Application);
  Result := DLLForm;
end;

in your main app:
procedure TForm1.Button1Click(Sender: TObject);
begin
  DLLForm := GetForm(Application.Handle, Application.Name);
  DLLForm.ManualDock(Panel1);
end;


A.
0
 
LVL 2

Expert Comment

by:333
ID: 1385383
sorry, forget about Application.Name, there is no such proerty (i have copied too much).
so it should be like:

in your DLL project:
function GetForm(AppHandle: THandle): TDLLForm;
begin
  Application.Handle:=AppHandle;
  DLLForm := TDLLForm.Create(Application);
  Result := DLLForm;
end;

in your main app:
procedure TForm1.Button1Click(Sender: TObject);
begin
  DLLForm := GetForm(Application.Handle);
  DLLForm.ManualDock(Panel1);
end;

A.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385384
Hi Jimmy,

This is just way to get around your scrollbox problem:


procedure TForm1.Button1Click(Sender: TObject);
var hostcontrol: TWinControl;
begin
  hostcontrol := ScrollBox1;
  DLLForm := GetForm(hostcontrol);
  DLLForm.BorderStyle := bsNone;
  DLLForm.AutoSize := true;
  if hostcontrol is TScrollingWinControl then
    with (hostcontrol as TScrollingWinControl) do
    begin
      HorzScrollBar.Range := DLLForm.Width;
      VertScrollBar.Range := DLLForm.Height;
    end;
end;

0
 

Expert Comment

by:PROGRAMMING030999
ID: 1385385
Hi all,
I try all of your examples and I can't get one to run.
All I get is an Access Exception.
Sorry JimmyC it is not my Question, but please could anybody send me a working example.

I will give 50 Points.
m.krech@mit.de

TIA Michael

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1385386
PROGRAMMING, I sent it to you
Please post a 50 point question if you get the interface to work.
0
 

Author Comment

by:JimmyC
ID: 1385387
Hi everyone,

Madshi/Epsylon, I've be trying/using your examples the past few days and I am quite satisfied with the results. I will decide later about the amount of points.

333, I tried that already before I posted this question but it does not work. Thanks anyway.

If someone has any other/aditional ideas/suggestions, he/she will still be in the race for (more) points so be quick. I leave this question open for 1 more day.

Cheers everyone,

Jimmy.
0
 

Author Comment

by:JimmyC
ID: 1385388
Alright, my app and plug-ins are making progress now. I want to give Epsylon 250 points ans Madshi 150 points for your help.

Epsylon, answer this one.
Madshi, I posted a new question for you.

Jimmy.
0
 

Author Comment

by:JimmyC
ID: 1385389
Adjusted points to 250
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 1000 total points
ID: 1385390
Thanks Jimmy, please grade me an 'A' for maximum points (4 x 250)

Cheers,

Epsylon.
0
 

Author Comment

by:JimmyC
ID: 1385391
Done  :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
Before we dive into the marketing strategies involved with creating an effective homepage, it’s crucial that EE members know what a homepage is. In essence, a homepage is the introductory, or default page, of a website that typically highlights the …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
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

730 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