Hello,
the other day I spent hours troubleshooting a problem with a WPF Visual Plugin that was not being displayed in a Delphi host.
I finally got it to work, but I do not understand why/how my change ‘fixed’ the problem.
My WPF VisualPlugin implements a custom interface: IPartGridView.
This is the class declaration:
[Plugin, VisualPlugin, NeedsManagedWrapper(typeof(PartGridVisualPluginWrapper))]
public partial class PartGridVisualPlugin : IPartGridView
{
// ...
}
This following delphi code is what I was originally using to instantiate the Visual-Plugin.
FDotNetPartGrid is a member variable of type: IPartGridView.
The problem was that the WPF control was not displayed at all.
procedure TApmControlPartGrid.BootUp;
var
VisualPlugin: IHYVisualPlugin;
begin
VisualPlugin := TJobUIFactory.CreatePartGridVisualPlugin;
VisualPlugin.ShowParented(FPanelHost);
FDotNetPartGrid := VisualPlugin as IPartGridView; // FDotNetPartGrid should point to the same object as VisualPlugin, or not???
FInitialized := False;
end;
As soon as I added FVisualPlugin as a member variable of type IHYVisualPlugin it suddenly worked:
procedure TApmControlPartGrid.BootUp;
begin
FVisualPlugin := TJobUIFactory.CreatePartGridVisualPlugin; // keep a reference to the Visual Plugin
FVisualPlugin.ShowParented(FPanelHost);
FDotNetPartGrid := FVisualPlugin as IPartGridView;
FInitialized := False;
end;
But this is the part which I do not understand.
Aren’t the FVisualPlugin and the FDotNetPartGrid pointing at the same .NET object?
Does this maybe have something to do with the NeedsManagedWrapper attribute?
Anyhow, it is working just fine now, but I would just like to understand.
Thank you!