在Delphi中,我希望处理菜单项的TMenuItem.Action.Visible属性的更改。这将作为弹出菜单项放置在TAdvGlowButton.DropDownMenu属性中。
首先,我尝试使用TAction的OnUpdate事件,但这在菜单弹出时引发得太晚了,而不是在Visible属性的更改真正完成时引发。
此外,用同时执行源处理程序和自己的处理程序的处理程序覆盖菜单项的ActionLink.OnChange属性也没有帮助。
有没有人有办法解决这个问题?
我希望在设置Visible属性时引发事件处理程序,而不仅仅是在弹出菜单时引发。
这些动作不是我创建的。因此,我无法更改它们的类型以使此事件可从外部访问(受保护的->公共)。
发布于 2020-01-27 22:33:33
更改操作的Visible属性的最明显的地方是它的OnChange事件。不幸的是,这个事件不是public,更不用说published了。
但是,有一种方法可以使用class helper将事件处理程序设置为OnChange事件。
在新的(或合适的现有)单元中创建class helper。这是一个有效的示例:
unit ActionHelper;
interface
type
TActionHelper = class helper for TBasicAction
private
function GetOnChange: TNotifyEvent;
procedure SetOnChange(const Value: TNotifyEvent);
public
property OnChange: TNotifyEvent read GetOnChange write SetOnChange;
end;
implementation
function TActionHelper.GetOnChange: TNotifyEvent;
begin
Result := inherited OnChange;
end;
procedure TActionHelper.SetOnChange(const Value: TNotifyEvent);
begin
inherited OnChange := Value;
end;
end.无论何时将此单元添加到US子句中,都可以将任何TBasicAction子体的OnChange属性连接到适当的事件处理程序。
尽管这个till不允许在Object Inspector中连接OnChange事件,但它是一种非常方便的方式,可以在某些操作属性发生变化时得到通知。
https://stackoverflow.com/questions/59930463
复制相似问题