我的英语不好所以我尽量简短。
当位于构造函数中时会失败:
fNTAServices.AddActionMenu('ViewToolWindowsItem', nil, CustomMenuItem);
因为在调用插件构造函数时主菜单尚未完全创建。
我在toolsapi中没有看到任何“IDE Ready”通知程序,因此我使用IOTAIDENotifier,当NotifyCode为ofnEndProjectGroupOpen时,它会调用AddActionMenu(一次)。
有更好的办法吗?
PS.
该插件是一个 dll,而不是一个包
这就是 GExperts 处理此问题的方式:
constructor TGExperts.Create;
begin
inherited Create;
FStartingUp := True;
InitializeGExperts;
// No idea where these 1200 ms came from, but
// basically it means that the method will be
// called when the application handles events
// the first time.
TTimedCallback.Create(DoAfterIDEInitialized, 1200, True);
end;
TTimedCallback.Create 创建一个 TTimer 并向其 OnTimer 事件添加代码,该事件调用 DoAfterIDEInitialized,然后释放计时器。
我不知道这是否是最好的解决方案,我只是继承了以前的开发人员的代码(关于 1200 毫秒的评论是我的)。我只能说它有效。