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

x
?
Solved

Help me, please !!!!!!

Posted on 1999-07-14
34
Medium Priority
?
264 Views
Last Modified: 2013-11-18
I have wrote a project to make plugable applications, and the plug-in is a .dll:

{*****************************************************}
library Plugin;

uses
  SysUtils, Classes, StdCtrls, Controls, Buttons;

type
  TMyControl = class(TBitBtn)
  protected
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;

constructor TMyControl.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
end;

destructor TMyControl.Destroy;
begin
  inherited Destroy;
end;

function CreatePlugin(AOwner: TComponent): TControl;
begin
  Result := TControl.Create(AOwner);
end;

function SetPlugin(AOwner: TWinControl; Plugin: TControl): Boolean;
begin
  TMyControl(Plugin).ParentFont := False;
  TMyControl(Plugin).Parent     := AOwner;
  Result := True;
end;

function FreePlugin(Plugin: TControl): Boolean;
begin
  Plugin.Free;
  Result := True;
end;

exports
  CreatePlugin, SetPlugin, FreePlugin;
end.

{******************************************************}
And I want to use this plug-in in a project, so the demo like this:

{******************************************************}
unit main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  TCreatePlugin = function(AOwner: TComponent): TControl;
  TSetPlugin = function(AOwner: TWinControl; Plugin: TControl): Boolean;
  TFreePlugin = function(Plugin: TControl): Boolean;

var
  Form1: TForm1;
  CreatePlugin: TCreatePlugin;
  SetPlugin:    TSetPlugin;
  FreePlugin:   TFreePlugin;

  DLL: THandle;
  Plugin: TControl;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Plugin := CreatePlugin(Form1);
  SetPlugin(Form1, Plugin);
  Plugin.Left := 0;
  Plugin.Top  := 0;
  Plugin.Width := 100;
  Plugin.Height := 100;
  Plugin.Visible := True;
  Caption := IntToStr(ControlCount);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  FreePlugin(Plugin);
  FreeLibrary(DLL);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  DLL := LoadLibrary('PLUGIN.DLL');
  CreatePlugin := GetProcAddress(DLL, 'CreatePlugin');
  SetPlugin    := GetProcAddress(DLL, 'SetPlugin');
  FreePlugin   := GetProcAddress(DLL, 'FreePlugin');
end;

end.

{**************************************************}
In this demo, I can use the plugin, but the controls are not visible, so the plugin can't work really!!

Somebody, please help me to fix it!
Thank you!!
0
Comment
Question by:piney
[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
  • 11
  • 10
  • 4
  • +5
34 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1388591
Listening...
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388592
I can offer you a much better solution than this. Please drop your email address here or send it to epsylon3@hotmail.com. I will send you a demo that saves a whole lot of trouble.

By the way, what Delphi version do you use?


Regards,

Epsylon.
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388593
piney,

Here's a better way to work with plugins:

Writing modularised applications
http://www.woden.com/~cubud/articles/plug.htm

I am confident the article above will shed some light on your problem, and, hopefully, you'll adopt another approach to the problem.

Yours,

Alex
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!

 

Author Comment

by:piney
ID: 1388594
Simonet:

  Your project is a good idea to make a plugable aplication, I will keep it.
  But, I want to use a new control designed in a .dll, and how to do it?
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1388595
hey simonet, why didn't you posted this url to my q'n too? :-(((
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1388596
Hi piney,

this is what COM objects are for. If you want to load an object which can be updated later (and thus put them in a DLL) then you need a mechanism to query the DLL or a kind of default object for its (new) properties/services. You can do it your own way or you can use the COM approach. The latter works so that you first ask the DLL for a specific "default" object/control (one that must have guaranteed methods and properties, but probably only a subset of the functionality you want to use). The DLL will then return this object to your application and you can ask this object then for more features it might support.

With this way you can write an application which can use the current functionality of an object. If you later enhance the object, then you don't need to rebuild the application as this will always ask for the "old" features, but every new application can ask for new features and use them (if available). If the new application only has an old DLL then it will still run, if it can work with the old feature set.

Does this help?

Ciao, Mike
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1388597
Forget to mention that if you only use the COM class in your own application you don't even need to register it with the system.

Ciao, Mike
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1388598
Lischke,

can you give a demo of what you're talking? Look at Q.10182446.

I'm very interested in your approach.

Zif.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1388599
Zif you got me :-) I never tried it myself this way (therefore I gave only a comment instead of an answer). What I did already, though, was to create a COM server (actually a shell extension).

I switch to the other question and we can discuss there, as I don't know if piney even like my idea.

Ciao, Mike
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388600
I have posted a Demo to Piney. Anyone else interested?
I would like to hear suggestions to enhance it.

Epsylon.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 1388601
Yes, post it to me too, please (public@lischke-online.de). Thanke you.

Ciao, Mike
0
 
LVL 4

Expert Comment

by:itamar
ID: 1388602
Hi all,

what about runtime packages ? I think the concept can be applicable here.

IHTH,
Itamar
0
 
LVL 15

Expert Comment

by:simonet
ID: 1388603
Zif, I didn't think that URL would help you. But I'll gladly accept the glories if it helped you! ;)))

Alex
0
 

Author Comment

by:piney
ID: 1388604
Epsylon:
  Your demo is good...
  But how can I create a new instance for my new class in the application? Because when I create a new instance in my application, it raise an error!
  And would you like to send me a demo showing how to make a really plugable application?
  Thank you!

Piney (piney@163.net)
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388605
I just sent a new version to Piney..... Anyone else?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388606
Piney, did you get it to work?
0
 

Author Comment

by:piney
ID: 1388607
Yes, Epsylon, I get the project. and it's cool.
First, sorry to answer your E-Mail so late, because I get on the NET only in my workroom, and I only work in Monday to Friday.
And in the project, my plant of it is creating some dynamic components in the form(like the control palettes), so can I make a IDE-like application(It seem to very hard to do it, but I would not like to use ActiveX). Because of my pool English and OOP programming, I hope you can help me.
I would like to get your new good ideas. Thank you for your helpping!


Yours Piney.
0
 

Author Comment

by:piney
ID: 1388608
Yes, Epsylon, I get the project. and it's cool.
First, sorry to answer your E-Mail so late, because I get on the NET only in my workroom, and I only work in Monday to Friday.
And in the project, my plant of it is creating some dynamic components in the form(like the control palettes), so can I make a IDE-like application(It seem to very hard to do it, but I would not like to use ActiveX). Because of my pool English and OOP programming, I hope you can help me.
I would like to get your new good ideas. Thank you for your helpping!


Yours Piney.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388609
Sorry, I do not understand what you are asking. I guess what you ask is already provided in the demo, so could you explain it again in other words?

Eps.
0
 

Author Comment

by:piney
ID: 1388610
Epsylon:
  As you know, when we get the plug-in(like create the plugin-form in the application), the new control class(TMyControl) is registered. Create new instances of the TMyConrtrol in my application(without create more plugin-forms), is all the means.
  Like this:

AControl := TControlClass(TTheMyControlClass).Create(Self);
AControl.Parent := MyApplicationForm;

  I hope you can understand my means.

Thank you.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388611
I don't think it is possible to do that. About 3 months ago I started some research on this whole thing and the only component I could 'transport' from a DLL was a form.
0
 

Author Comment

by:piney
ID: 1388612
 But how can I design a pluginable application using a package? How can I know what properties and methods in a new plugin control? And How can I use them?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388613
> But how can I design a pluginable application using a package?

A package is used to store components that, if you install them, appear in Delphi on the component palette. You can create them with: Component menu > NewComponent
and when ready install it with: Component menu > Install Component.


> How can I know what properties and methods in a new plugin control?

If you mean the properties that appear in the object inspector..... I will email a demo....

Eps.
0
 

Author Comment

by:piney
ID: 1388614
Sorry, I didn't clear my means, what I want is:
Using a new control class in runtime.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388615
With the CountDown as example you can create it at runtime with:

Uses CountDown;

var cdown: TCountDown;

cdown := TCountDown.Create;

etc.
0
 

Author Comment

by:piney
ID: 1388616
Making a plugin, at less we don't know how many properties and methods in it, in your demo, we should register a new control class in delphi's IDE before we begin to programming!This is I won't to do...
I want to make a package contained new control class(es), needn't register in IDE, insteat, we will register in our application, so our application can using pluginable controls.
Could you understand my pool English means?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388617
Well, I think what you want is not possible.....   :o(

When you create on object you need to know the class.
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1388618
You could compile your pluging component(s) into a dll (package), and export the Register procedure.
procedure Register;
begin
  RegisterClasses([TMyComponent], ...);
end;

The calling app can load the dll, locate and call the Register function. Then call GetClass("TMyComponent") to get a class variable.
You can then create an instance of that class.

Cheers,
Phil.

0
 

Author Comment

by:piney
ID: 1388619
Philipleighs
  Would you send me a demo?
0
 
LVL 3

Expert Comment

by:philipleighs
ID: 1388620
Sorry piney, I don't have time to prepare a demo for you.
Why don't you have a go?

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1388621
Epsylon:

Could you please send me your demo? raymond.wilson@trimble.co.nz

Cheers,

Raymond.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 1388622
Hi, I just tried something. Maybe it helps you...


var c: TWinControlClass;
    w: TWinControl;
begin
  RegisterClasses([TEdit]);
  c := TWinControlClass(GetClass('TEdit'));
  w := c.Create(Self);
  w.Parent := Self;
end;


Eps.
0
 

Author Comment

by:piney
ID: 1388623
Epsylon:
  Thank you! It's so cool!
  But how can I give you the expert points?
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 600 total points
ID: 1388624
Nice stuff indeed  :o)

Grade it now. I just locked this question.

Thanks for the points!


Cheers,

Epsylon.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

688 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