Thema: Delphi Hydra 3.0 Plugin

Einzelnen Beitrag anzeigen

hanspeter

Registriert seit: 26. Jul 2003
Ort: Leipzig
1.350 Beiträge
 
Delphi XE2 Professional
 
#10

Re: Hydra 3.0 Plugin

  Alt 17. Sep 2007, 15:05
Ich habe es mal schnell in ein bestehendes Projekt eingebunden und habe kein Problem.

1. Das Interface

Delphi-Quellcode:
  
type

  IListBoxInterface = interface
      ['{2993CFD4-EC29-42C2-BB49-707C9A254B4F}']
   procedure SetEditField(Parent: TWinControl;Edit: TEdit);
   function GetVersion: String;
  end;

implementation

end.
2. Das Plugin

Delphi-Quellcode:
type
  TMyListBoxPlugin = class(THYVisualPlugin, IListBoxInterface)
    Edit1: TEdit;
    ListBox1: TListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
  protected
  public
    procedure SetEditField(Parent: TWinControl;Edit: TEdit);
    function Getversion: string;
  end;
Die Funktion selber:

Delphi-Quellcode:
function TMyListBoxPlugin.Getversion: string;
begin
  result := '1.0';
end;

Und der Aufruf im Host

Delphi-Quellcode:
 

var
  FListIfForm : IListBoxInterface;

with ModuleManager do begin
    // Loads the module
    LoadModule('VisualModule.dll');
    CreateVisualPlugin('MyListBoxPlugin', fListForm);
    FListIfForm := fListForm as IListBoxInterface;
    fListForm.ShowParented(Panel1);
Der Aufruf : Edit2.Text := FListIfForm.GetVersion;


Das entsorgen:

Delphi-Quellcode:
 
  FListIfForm := nil; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  ModuleManager.ReleaseInstance(fListForm);
  // Unloads the module
  ModuleManager.UnloadModules;
Der Fehler kommt, weil das Interface (eigene Referenzzählung) getrennt entsorgt werden muss.
Also den Referenzzeiger auf nil setzen und dann erst den Rest entsorgen.

Gruß Peter
  Mit Zitat antworten Zitat