2

我正在使用 Delphi XE IDE。我创建了一个通知器来实现 IOTACompileNotifier。在 IDE 中安装专家后。当我编译我的项目时,代码工作正常。通知程序正在为 ProjectCompileStarted 工作。

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

[Fatal Error] Access violation at address 21B7FBED in module 'delphicoreide150.bpl'. Read of address 00000000

虽然我的表现看起来很奇怪:

var i: integer;
begin
  i := Project.ProjectBuilder.AddCompileNotifier(TProjectCompileNotifier.Create);
  Project.ProjectBuilder.RemoveCompileNotifier(i);
end;

在通知者中。我只想显示无论我如何使用,ProjectBuilder 的 Add and Remove compile notifier 似乎都无法正常工作。

请告知我应该如何实施 IOTAProjectCompileNotifier。

谢谢你。

以下是完整的源代码:

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.
4

3 回答 3

4

我想我或许可以回答这个问题。我没有 XE,所以我似乎没有IOTAProjectCompileNotifier. 但是,AddNotifier我的 ToolsAPI 单元中的其他方法建议将其声明为:

function AddNotifier(const ANotifier: IOTAProjectCompileNotifier): Integer;

你这样调用这个例程:

i := Project.ProjectBuilder.AddCompileNotifier(TProjectCompileNotifier.Create);

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

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;

您需要在初始化/完成代码中做同样的事情。

我相信这确实应该被认为是接口引用计数实现中的一个错误。它已在 Stack Overflow 上多次讨论过。

于 2011-03-26T11:09:34.517 回答
3

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

于 2011-03-26T11:29:08.123 回答
0

错误代码“读取地址 00000000”可能表明您正在尝试访问不存在的资源。我看到你在 Embarcadero 论坛上问过同样的问题。就我在SO上看到的,只有几个开发者对OTA感兴趣,CG或Embarcadero的文档几乎没有,所以我建议你坚持Embarcadero的论坛。

最好的问候,
拉杜

于 2011-03-26T10:35:54.290 回答