Delphi OpenTools API:如何获取 AfterCompile 通知?

发布于 2024-12-13 05:13:49 字数 2641 浏览 2 评论 0原文

OpenTools API 定义了一个接口,用于在编译之前之后收到通知:

IOTAIDENotifier = interface(IOTANotifier)
  ['{E052204F-ECE9-11D1-AB19-00C04FB16FB3}']
  procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);  // This procedure is called for many various file operations within the IDE
  procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload; // This function is called immediatately before the compiler is invoked. Set Cancel to True to cancel the compile
  procedure AfterCompile(Succeeded: Boolean); overload; // This procedure is called immediately following a compile.  Succeeded will be true if the compile was successful
end;

我创建了一个导出此接口的向导:

TDBGExportWizard = class(TNotifierObject, IOTANotifier, IOTAIDENotifier, IOTAIDENotifier50, IOTAWizard)
public
   { IOTANotifier }
// procedure AfterSave; //This procedure is called immediately after the item is successfully saved. This is not called for IOTAWizards
// procedure BeforeSave; //This function is called immediately before the item is saved. This is not called for IOTAWizard
// procedure Destroyed; // The associated item is being destroyed so all references should be dropped. Exceptions are ignored.
// procedure Modified; // This associated item was modified in some way. This is not called for IOTAWizards

   { IOTAIDENotifier }
   procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
   procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload;
   procedure AfterCompile(Succeeded: Boolean); overload;

   { IOTAIDENotifier50 }
   procedure BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean; var Cancel: Boolean); overload;
   procedure AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean); overload;

   { IOTAWizard }
   function GetIDString: string;
   function GetName: string;
   function GetState: TWizardState;
   procedure Execute;
end;

并注册该向导:

procedure Register;
begin
   RegisterPackageWizard(TDBGExportWizard.Create);
end;

但两者都没有:

  • <代码>IOTAIDENotifier.BeforeCompile
  • IOTAIDENotifier.AfterCompile
  • IOTAIDENotifier.FileNotification
  • IOTAIDENotifier50.BeforeCompile
  • IOTAIDENotifier50.AfterCompile

调用 。我做错了什么?


唯一调用的是

  • IOTAWizard.GetName
  • IOTAWizard.GetIDString

按此顺序。

The OpenTools API defines an interface for being notified before and after a compile:

IOTAIDENotifier = interface(IOTANotifier)
  ['{E052204F-ECE9-11D1-AB19-00C04FB16FB3}']
  procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);  // This procedure is called for many various file operations within the IDE
  procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload; // This function is called immediatately before the compiler is invoked. Set Cancel to True to cancel the compile
  procedure AfterCompile(Succeeded: Boolean); overload; // This procedure is called immediately following a compile.  Succeeded will be true if the compile was successful
end;

i've created a wizard that exports this interface:

TDBGExportWizard = class(TNotifierObject, IOTANotifier, IOTAIDENotifier, IOTAIDENotifier50, IOTAWizard)
public
   { IOTANotifier }
// procedure AfterSave; //This procedure is called immediately after the item is successfully saved. This is not called for IOTAWizards
// procedure BeforeSave; //This function is called immediately before the item is saved. This is not called for IOTAWizard
// procedure Destroyed; // The associated item is being destroyed so all references should be dropped. Exceptions are ignored.
// procedure Modified; // This associated item was modified in some way. This is not called for IOTAWizards

   { IOTAIDENotifier }
   procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
   procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload;
   procedure AfterCompile(Succeeded: Boolean); overload;

   { IOTAIDENotifier50 }
   procedure BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean; var Cancel: Boolean); overload;
   procedure AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean); overload;

   { IOTAWizard }
   function GetIDString: string;
   function GetName: string;
   function GetState: TWizardState;
   procedure Execute;
end;

and register the wizard with:

procedure Register;
begin
   RegisterPackageWizard(TDBGExportWizard.Create);
end;

But neither:

  • IOTAIDENotifier.BeforeCompile
  • IOTAIDENotifier.AfterCompile
  • IOTAIDENotifier.FileNotification
  • IOTAIDENotifier50.BeforeCompile
  • IOTAIDENotifier50.AfterCompile

are called. What am i doing wrong?


The only thing ever called is

  • IOTAWizard.GetName
  • IOTAWizard.GetIDString

In that order.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木有鱼丸 2024-12-20 05:13:49

以下内容来自我们软件的一小部分(我剪掉了一些代码,但它应该可以工作)

unit UnitSymbolInsert;

interface

procedure Register;

implementation

uses
  SysUtils, ToolsApi, Classes, Types, ActiveX, UnitSymbols;

type
  TCITNotifier = class(TNotifierObject, IOTANotifier, IOTAIDENotifier, IOTAIDENotifier50 )
  protected
    // IOTAIDENotifier
    procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
    procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload;
    procedure AfterCompile(Succeeded: Boolean); overload;
    // IOTAIDENotifier50
    procedure BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean; var Cancel: Boolean); overload;
    procedure AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean); overload;
  end;

var
  NotifierIndex: Integer = -1;

procedure Register;
var
  Services: IOTAServices;
begin
  if not Supports(BorlandIDEServices, IOTAServices, Services) then Exit;
  NotifierIndex := Services.AddNotifier(TCITNotifier.Create);
end;

procedure UnRegister;
var
  Services: IOTAServices;
begin
  if (NotifierIndex < 0) or not Supports(BorlandIDEServices, IOTAServices, Services) then Exit;
  Services.RemoveNotifier(NotifierIndex);
end;

{ TCITNotifier }

procedure TCITNotifier.AfterCompile(Succeeded, IsCodeInsight: Boolean);
begin
  // Only when we have a succesfully build for a project.
  if not Succeeded or IsCodeInsight then Exit;

  // do something useful here!!!!
end;

procedure TCITNotifier.BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean; var Cancel: Boolean);
begin
  // Not used
end;

procedure TCITNotifier.AfterCompile(Succeeded: Boolean);
begin
  // Not used
end;

procedure TCITNotifier.BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
begin
  // Not used
end;

procedure TCITNotifier.FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
begin
  // Not used
end;

initialization
  ;
finalization
  UnRegister;
end.

希望我没有剪掉太多。
构建成 dpk 并将其安装到 IDE 中。

The following Is from a small piece of our software (I clipped out some code but it should work)

unit UnitSymbolInsert;

interface

procedure Register;

implementation

uses
  SysUtils, ToolsApi, Classes, Types, ActiveX, UnitSymbols;

type
  TCITNotifier = class(TNotifierObject, IOTANotifier, IOTAIDENotifier, IOTAIDENotifier50 )
  protected
    // IOTAIDENotifier
    procedure FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
    procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean); overload;
    procedure AfterCompile(Succeeded: Boolean); overload;
    // IOTAIDENotifier50
    procedure BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean; var Cancel: Boolean); overload;
    procedure AfterCompile(Succeeded: Boolean; IsCodeInsight: Boolean); overload;
  end;

var
  NotifierIndex: Integer = -1;

procedure Register;
var
  Services: IOTAServices;
begin
  if not Supports(BorlandIDEServices, IOTAServices, Services) then Exit;
  NotifierIndex := Services.AddNotifier(TCITNotifier.Create);
end;

procedure UnRegister;
var
  Services: IOTAServices;
begin
  if (NotifierIndex < 0) or not Supports(BorlandIDEServices, IOTAServices, Services) then Exit;
  Services.RemoveNotifier(NotifierIndex);
end;

{ TCITNotifier }

procedure TCITNotifier.AfterCompile(Succeeded, IsCodeInsight: Boolean);
begin
  // Only when we have a succesfully build for a project.
  if not Succeeded or IsCodeInsight then Exit;

  // do something useful here!!!!
end;

procedure TCITNotifier.BeforeCompile(const Project: IOTAProject; IsCodeInsight: Boolean; var Cancel: Boolean);
begin
  // Not used
end;

procedure TCITNotifier.AfterCompile(Succeeded: Boolean);
begin
  // Not used
end;

procedure TCITNotifier.BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
begin
  // Not used
end;

procedure TCITNotifier.FileNotification(NotifyCode: TOTAFileNotification; const FileName: string; var Cancel: Boolean);
begin
  // Not used
end;

initialization
  ;
finalization
  UnRegister;
end.

Hopefully I did not clip away too much.
Build into a dpk and install it into the IDE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文