Help me, please !!!!!!

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!!
pineyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rwilson032697Commented:
Listening...
0
EpsylonCommented:
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
simonetCommented:
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
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

pineyAuthor Commented:
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
ZifNabCommented:
hey simonet, why didn't you posted this url to my q'n too? :-(((
0
LischkeCommented:
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
LischkeCommented:
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
ZifNabCommented:
Lischke,

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

I'm very interested in your approach.

Zif.
0
LischkeCommented:
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
EpsylonCommented:
I have posted a Demo to Piney. Anyone else interested?
I would like to hear suggestions to enhance it.

Epsylon.
0
LischkeCommented:
Yes, post it to me too, please (public@lischke-online.de). Thanke you.

Ciao, Mike
0
itamarCommented:
Hi all,

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

IHTH,
Itamar
0
simonetCommented:
Zif, I didn't think that URL would help you. But I'll gladly accept the glories if it helped you! ;)))

Alex
0
pineyAuthor Commented:
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
EpsylonCommented:
I just sent a new version to Piney..... Anyone else?
0
EpsylonCommented:
Piney, did you get it to work?
0
pineyAuthor Commented:
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
pineyAuthor Commented:
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
EpsylonCommented:
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
pineyAuthor Commented:
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
EpsylonCommented:
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
pineyAuthor Commented:
 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
EpsylonCommented:
> 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
pineyAuthor Commented:
Sorry, I didn't clear my means, what I want is:
Using a new control class in runtime.
0
EpsylonCommented:
With the CountDown as example you can create it at runtime with:

Uses CountDown;

var cdown: TCountDown;

cdown := TCountDown.Create;

etc.
0
pineyAuthor Commented:
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
EpsylonCommented:
Well, I think what you want is not possible.....   :o(

When you create on object you need to know the class.
0
philipleighsCommented:
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
pineyAuthor Commented:
Philipleighs
  Would you send me a demo?
0
philipleighsCommented:
Sorry piney, I don't have time to prepare a demo for you.
Why don't you have a go?

0
rwilson032697Commented:
Epsylon:

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

Cheers,

Raymond.

0
EpsylonCommented:
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
pineyAuthor Commented:
Epsylon:
  Thank you! It's so cool!
  But how can I give you the expert points?
0
EpsylonCommented:
Nice stuff indeed  :o)

Grade it now. I just locked this question.

Thanks for the points!


Cheers,

Epsylon.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.