TForm dans une DLL avec utilisation d'Interface
J'ai repris le tutorial de sjrd pour créer des plugins graphiques le composant que j'utilise comme base pour mes plugins est un TForm parce que ainsi je peux créer mes plugins en designe dans delphi comme pour une forme classique delphi.
Tout ceci fonctionne très bien mis à part quand je place mon plugin dans une scrollbox là la les scrollbars disparaisse quand je suis en bout de course...
Quelqu'un peux m'aider
http://sjrd.developpez.com/delphi/de...s/compoplugin/
Voici le code de l'interface
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
unit PluginIntf;
interface
uses
Classes,
Forms;
type
IPlugin = interface
['{11B9838C-CD8E-4F6C-BDF8-8774A671E825}']
function GetComponent : TForm;stdcall;
property Component : TForm read GetComponent;
end;
TCreatePlugin=function(AOwner:TComponent) : IPlugin;stdcall;
implementation
end. |
La classe qui me charge le plugin
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
unit PluginClass;
interface
uses
Windows,
Classes,
PluginIntf;
type
TPlugin = class
private
FHandle : THandle;
FCreate : TCreatePlugin;
FPlugin : IPlugin;
public
Constructor Create(AOwner:TComponent;Filename : String);
Destructor Destroy;override;
property Instance : IPlugin read FPlugin write FPlugin;
end;
implementation
{ TPlugin }
constructor TPlugin.Create(AOwner:TComponent;Filename: String);
begin
Filename := Filename + '.dll';
FHandle := LoadLibrary(PChar(Filename));
if FHandle <> 0 then
begin
FCreate := GetProcAddress(FHandle,'CreatePlugin');
if @FCreate <> nil then
begin
FPlugin := FCreate(AOwner);
end;
end;
end;
destructor TPlugin.Destroy;
begin
FPlugin := nil;
if FHandle <> 0 then
FreeLibrary(FHandle);
end;
end. |
La forme sur laquelle le plugin va etre placé
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
unit Unit1;
interface
uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
PluginClass,
PluginIntf, StdCtrls;
type
TForm1 = class(TForm)
ScrollBox1: TScrollBox;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
public
Plug : TPlugin;
end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Plug <> nil then with Plug.Instance.Component do
begin
ParentWindow := 0;
Windows.SetParent(Handle, 0);
end;
Plug.Instance := nil;
Plug.Destroy;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Plug := TPlugin.Create(Self,'Project2');
Plug.Instance.Component.Parent := ScrollBox1;
with Plug.Instance.Component do
begin
ParentWindow := ScrollBox1.Handle;
Windows.SetParent(Handle,ScrollBox1.Handle);
Left := 0;
Top := 0;
Visible := True;
end;
end;
end. |