首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何实现Delphi的ToolsAPI的IOTAProjectCompileNotifier?

如何实现Delphi的ToolsAPI的IOTAProjectCompileNotifier?
EN

Stack Overflow用户
提问于 2011-03-26 09:03:13
回答 3查看 1.1K关注 0票数 2

我使用的是Delphi XE IDE。我创建了一个通知程序来实现IOTACompileNotifier。在IDE中安装expert之后。当我编译我的项目时,代码运行得很好。通知程序正在为ProjectCompileStarted工作。

第二次编译我的项目时,Delphi IDE提示:

代码语言:javascript
复制
[Fatal Error] Access violation at address 21B7FBED in module 'delphicoreide150.bpl'. Read of address 00000000

尽管我的表演看起来很奇怪:

代码语言:javascript
复制
var i: integer;
begin
  i := Project.ProjectBuilder.AddCompileNotifier(TProjectCompileNotifier.Create);
  Project.ProjectBuilder.RemoveCompileNotifier(i);
end;

在通知程序中。我只想显示添加和删除ProjectBuilder的编译通知程序似乎不能正常工作,无论我如何使用。

请建议我应该如何实现IOTAProjectCompileNotifier。

谢谢。

以下是完整的源代码:

代码语言:javascript
复制
type
  TProjectCompileNotifier = class(TInterfacedObject, IOTAProjectCompileNotifier)
  protected
    procedure AfterCompile(var CompileInfo: TOTAProjectCompileInfo);
    procedure BeforeCompile(var CompileInfo: TOTAProjectCompileInfo);
    procedure Destroyed;
  end;

  TCompileNotifier = class(TInterfacedObject, IOTACompileNotifier)
  protected
    procedure ProjectCompileStarted(const Project: IOTAProject; Mode: TOTACompileMode);
    procedure ProjectCompileFinished(const Project: IOTAProject; Result: TOTACompileResult);
    procedure ProjectGroupCompileStarted(Mode: TOTACompileMode);
    procedure ProjectGroupCompileFinished(Result: TOTACompileResult);
  end;

procedure TCompileNotifier.ProjectCompileStarted(const Project: IOTAProject;
  Mode: TOTACompileMode);
var i: integer;
begin
  i := Project.ProjectBuilder.AddCompileNotifier(TProjectCompileNotifier.Create);
  Project.ProjectBuilder.RemoveCompileNotifier(i);
end;

var i: integer;

initialization
  i := (BorlandIDEServices as IOTACompileServices).AddNotifier(TCompileNotifier.Create);
finalization
  (BorlandIDEServices as IOTACompileServices).RemoveNotifier(i);
end.
EN

回答 3

Stack Overflow用户

发布于 2011-03-26 19:09:35

我想我也许能回答这个问题。我没有XE,所以我看起来没有IOTAProjectCompileNotifier。但是,我的ToolsAPI单元中的其他AddNotifier方法建议将其声明为:

代码语言:javascript
复制
function AddNotifier(const ANotifier: IOTAProjectCompileNotifier): Integer;

您可以这样调用此例程:

代码语言:javascript
复制
i := Project.ProjectBuilder.AddCompileNotifier(TProjectCompileNotifier.Create);

问题是没有任何东西引用TProjectCompileNotifier.Create返回的接口。您需要这样做,如下所示:

代码语言:javascript
复制
procedure TCompileNotifier.ProjectCompileStarted(const Project: IOTAProject; Mode: TOTACompileMode);
var
  i: integer;
  Intf: IOTAProjectCompileNotifier;
begin
  Intf := TProjectCompileNotifier.Create;
  i := Project.ProjectBuilder.AddCompileNotifier(Intf);
  Project.ProjectBuilder.RemoveCompileNotifier(i);
end;

您需要在初始化/结束代码中执行同样的操作。

我认为这真的应该被认为是接口引用计数实现中的一个错误。它已经被discussed here on Stack Overflow很多次了。

票数 4
EN

Stack Overflow用户

发布于 2011-03-26 19:29:08

我想知道为什么您要从回调中删除通知程序。我可以想象OTA不能很好地处理这种情况。尝试以下操作:首先(在加载和初始化包时)安装一个IOTAIDENotifier,以便在项目打开时得到通知(在完成时将其删除)。实现它的FileNotification以在项目打开时添加IOTAProjectCompileNotifier,在项目关闭时删除它。

票数 3
EN

Stack Overflow用户

发布于 2011-03-26 18:35:54

错误代码"Read of address 00000000“可能表示您正在尝试访问不存在的资源。我看到你在Embarcadero论坛上问了同样的问题。从我在这里看到的SO,只有几个开发人员对OTA感兴趣,CG或Embarcadero的文档几乎不存在,所以我建议你坚持使用Embarcadero的论坛。

诚挚的问候,

Radu

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5439666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档