Get visual plugin associated with THYPluginPanel

Given an instance of THYPluginPanel, is there a way to get the associated visual plugin? I’d like to locate the plugin that currently has focus when my Delphi ActionMainMenuBar menus pop (e.g., click the Edit menu and the options are enabled or disabled based on the target).

Here’s sample code that I’m using which overrides TEditCut:

unit TMyEditCut;

interface

uses
Winapi.Windows, System.SysUtils, Vcl.Forms, StdActns, Tx4oleLib_TLB, uHYCLRManagedPluginWrappers;

type
TEditCut = class(StdActns.TEditCut)
public
function HandlesTarget(Target: TObject): Boolean; override;
procedure ExecuteTarget(Target: TObject); override;
procedure UpdateTarget(Target: TObject); override;
end;

implementation

function TEditCut.HandlesTarget(Target: TObject): Boolean;
begin
OutputDebugString(PChar(Format(‘TEditCut.HandlesTarget() - Class: %s’, [Target.ClassName])));
result := (inherited handlesTarget(Target)) or (Target is THYPluginPanel);
end;

procedure TEditCut.ExecuteTarget(Target: TObject);
var
PluginPanel: THYPluginPanel;
begin
OutputDebugString(PChar(Format(‘TEditCut.ExecuteTarget() - Class: %s’, [Target.ClassName])));
if Target.ClassType = THYPluginPanel then begin
// nothing yet
end else
inherited;
end;

procedure TEditCut.UpdateTarget(Target: TObject);
begin
OutputDebugString(PChar(Format(‘TEditCut.UpdateTarget() - Class: %s’, [Target.ClassName])));
if Target.ClassType = THYPluginPanel then
// nothing yet
else
inherited;
end;

end.

I found one way that I think will work reliably in my case, but I wonder if there’s an easier/better way? I use the THYPluginPanel.Parent property and then check this value, which is a subclass of TFrame in my case. Depending on the subclass type, then I can assume the plugin type and invoke different methods from my custom Hydra plugin interface. An example:

procedure TEditCut.UpdateTarget(Target: TObject);
var
PluginPanel: THYPluginPanel;
begin
OutputDebugString(PChar(Format(‘TEditCut.UpdateTarget() - Class: %s’, [Target.ClassName])));
if Target.ClassType = THYPluginPanel then begin
PluginPanel := (Target as THYPluginPanel);
if PluginPanel.Parent is TTextFrame then
Enabled := TTextFrame(PluginPanel.Parent).CanCut
else
Enabled := False;
end else
inherited;
end;