我使用的是Delphi XE IDE。我创建了一个通知程序来实现IOTACompileNotifier。在IDE中安装expert之后。当我编译我的项目时,代码运行得很好。通知程序正在为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的编译通知程序似乎不能正常工作,无论我如何使用。
请建议我应该如何实现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.发布于 2011-03-26 19:09:35
我想我也许能回答这个问题。我没有XE,所以我看起来没有IOTAProjectCompileNotifier。但是,我的ToolsAPI单元中的其他AddNotifier方法建议将其声明为:
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;您需要在初始化/结束代码中执行同样的操作。
我认为这真的应该被认为是接口引用计数实现中的一个错误。它已经被discussed here on Stack Overflow很多次了。
发布于 2011-03-26 19:29:08
我想知道为什么您要从回调中删除通知程序。我可以想象OTA不能很好地处理这种情况。尝试以下操作:首先(在加载和初始化包时)安装一个IOTAIDENotifier,以便在项目打开时得到通知(在完成时将其删除)。实现它的FileNotification以在项目打开时添加IOTAProjectCompileNotifier,在项目关闭时删除它。
发布于 2011-03-26 18:35:54
错误代码"Read of address 00000000“可能表示您正在尝试访问不存在的资源。我看到你在Embarcadero论坛上问了同样的问题。从我在这里看到的SO,只有几个开发人员对OTA感兴趣,CG或Embarcadero的文档几乎不存在,所以我建议你坚持使用Embarcadero的论坛。
诚挚的问候,
Radu
https://stackoverflow.com/questions/5439666
复制相似问题