Hi,
I’m looking at migrating my .Net Oxygene plugins from a Delphi host application into a .Net Oxygene host. Should be relatively straight forward, but I run in to a System.InvalidCastException everytime I try to call a method on a plugin.
I have reverted to looking at the ManagedOxygeneHost sample application and trying to load a simple plugin with one interface defined. That also gives me the same issue :-
The only modifications to the sample host application are to add the code file containing the interface definition and call it from method MainForm.lb_Plugins_DoubleClick
i.e.
namespace DUF003;
uses
RemObjects.Hydra.CrossPlatform,
System.Runtime.InteropServices;
interface
type
[Guid('37E83B67-4943-43AB-9AF6-EBAF981BF793')]
IMessageProcessor = public interface(IHYCrossPlatformInterface)
method ProcessMessage(Message: String);
end;
implementation
end.
and call the plugin from the double click method with :-
self.fCurrentPlugin := self.moduleManager1.CreateInstance(PluginDescriptor(self.lb_Plugins.SelectedItem));
self.pnl_Host.HostPlugin(self.fCurrentPlugin);
(self.fCurrentPlugin as DUF003.IMessageProcessor).ProcessMessage('BOO !');
As you can see, the module instance loads OK and is hosted in the panel (it just has a simple label with “CAT001 Test” as the caption). The exception occurs on the above line of code, which also occurs in my real world code.
Other points that may be relevant :-
In my real world code, I have looked at the interfaces supported by the plugin and my interfaces are listed i.e. the code below would list the IMessageProcessor interface in a listbox.
var objType: &Type := typeOf(self.CurrentPlugin);
// Getting interface of specified name
// using GetField(String) Method
var minterface: array of &Type := objType.GetInterfaces();
for i: Integer := 0 to minterface.Length - 1 do
listInfo.Items.Add(minterface[i]);
The “Import Plugin Interface” does not seem to work :-
If I import the .pas file containing the interface listed above, all I get is a file with the code shown below. I therefore link to the plugin unit containing the interface definition i.e. the file shown above (in the DUF003 namespace).
namespace ManagedHost;
// Imported cross-patform Hydra plugin interfaces
// Some interfaces may not be imported or imported incorrectly due to the following issues:
// [1:1] Unit expected
//
interface
implementation
end.
I also modified the AssemblyInfo.pas of the host application to include
[assembly: ComVisible(true)]
which I believe is as per the “passing interfaces” documentation.
Can you suggest how to move forward (or supply a very simple host / plugin Oxygene sample that works when calling a method on the plugin) ?