Link to home
Start Free TrialLog in
Avatar of piney
piney

asked on

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!!
Avatar of rwilson032697
rwilson032697

Listening...
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.
Avatar of simonet
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
Avatar of piney

ASKER

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

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

I'm very interested in your approach.

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

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

Ciao, Mike
Hi all,

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

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

Alex
Avatar of piney

ASKER

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)
I just sent a new version to Piney..... Anyone else?
Piney, did you get it to work?
Avatar of piney

ASKER

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.
Avatar of piney

ASKER

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.
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.
Avatar of piney

ASKER

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.
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.
Avatar of piney

ASKER

 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?
> 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.
Avatar of piney

ASKER

Sorry, I didn't clear my means, what I want is:
Using a new control class in runtime.
With the CountDown as example you can create it at runtime with:

Uses CountDown;

var cdown: TCountDown;

cdown := TCountDown.Create;

etc.
Avatar of piney

ASKER

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?
Well, I think what you want is not possible.....   :o(

When you create on object you need to know the class.
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.

Avatar of piney

ASKER

Philipleighs
  Would you send me a demo?
Sorry piney, I don't have time to prepare a demo for you.
Why don't you have a go?

Epsylon:

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

Cheers,

Raymond.

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.
Avatar of piney

ASKER

Epsylon:
  Thank you! It's so cool!
  But how can I give you the expert points?
ASKER CERTIFIED SOLUTION
Avatar of Epsylon
Epsylon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial