-2

我正在做关于扩展 IDE 的第一次测试,但我只发现使用ExptInftand的旧源代码ToolsIntf已被弃用(Delphi 2007)。

我正在寻找更新的示例代码或更新旧示例的帮助。

这是我为尝试更新旧示例所做的:

我从这个示例源代码开始:

unit PanelEd; 

interface 

uses 
  Classes, Forms, Windows, Dialogs, ExptIntf, ToolIntf, 
  FileCtrl, SysUtils, EditIntf, DsgnIntf; 

type 
  TPanelEditExpert = class (TIExpert) 
  public 
    function GetStyle: TExpertStyle; override; 
    function GetName: string; override; 
    function GetAuthor: string; override; 
    function GetComment: string; override; 
    function GetPage: string; override; 
    function GetGlyph: HICON; override; 
    function GetState: TExpertState; override; 
    function GetIDString: string; override; 
    function GetMenuText: string; override; 
    procedure Execute; override; 
  end; 

// custom module for the panel 
type 
  TPanelModule = class (TCustomModule) 
  public 
    procedure ExecuteVerb(Index: Integer); override; 
    function GetVerb(Index: Integer): string; override; 
    function GetVerbCount: Integer; override; 
    procedure ValidateComponent(Component: TComponent); override; 
  end; 

procedure Register; 

implementation 

uses 
  StdCtrls, ExtCtrls, Buttons; 

// "standard" project expert 

function TPanelEditExpert.GetStyle: TExpertStyle; 
begin 
  // show up in the Help menu 
  Result := esStandard; 
end; 

function TPanelEditExpert.GetName: String; 
begin 
  // official name 
  Result := 'Panel Edit Wizard' 
end; 

function TPanelEditExpert.GetAuthor: string; 
begin 
  Result := 'Marco and Tim'; 
end; 

function TPanelEditExpert.GetComment: String; 
begin 
  Result := 'TPanelEditExpert Wizard'; 
end; 

function TPanelEditExpert.GetPage: string; 
begin 
  Result := ''; 
end; 

function TPanelEditExpert.GetGlyph: HICON; 
begin 
  Result := 0; 
end; 

function TPanelEditExpert.GetState: TExpertState; 
begin 
  Result := [esEnabled]; 
end; 

function TPanelEditExpert.GetIDString: String; 
begin 
  // must be unique 
  Result := 'DDHandbook.PanelEditWizard' 
end; 

function TPanelEditExpert.GetMenuText: String; 
begin 
  // the text of the menu item 
  Result := '&Panel Edit Wizard' 
end; 

procedure TPanelEditExpert.Execute; 
var 
  ModuleName, FormName, FileName: string; 
  ModIntf: TIModuleInterface; 
begin 
  ToolServices.GetNewModuleAndClassName ( 
    'Panel', ModuleName, FormName, FileName); 
  ModIntf := ToolServices.CreateModuleEx (FileName, FormName, 
    'Panel', '', nil, nil, 
    [cmNewForm, cmAddToProject, cmUnNamed]); 
  ModIntf.ShowSource; 
  ModIntf.ShowForm; 
  ModIntf.Release; 
end; 

// custom module methods 

function TPanelModule.GetVerbCount: Integer; 
begin 
  Result := 1; 
end; 

function TPanelModule.GetVerb(Index: Integer): string; 
begin 
  if Index = 0 then 
    Result:= 'Rename...'; 
end; 

procedure TPanelModule.ExecuteVerb(Index: Integer); 
var 
  NewName: string; 
begin 
  if Index = 0 then 
  begin 
    NewName := Root.Name; 
    if InputQuery ('Panel Module Editor', 
        'New panel name:', NewName) then 
      Root.Name := NewName; 
  end; 
end; 

procedure TPanelModule.ValidateComponent(Component: TComponent); 
begin 
  if not (Component is TButton) and 
      not (Component is TSpeedButton) then 
    raise Exception.Create ('The panel can host only buttons'); 
end; 

procedure Register; 
begin 
  RegisterCustomModule (TPanel, TPanelModule); 
  RegisterLibraryExpert(TPanelEditExpert.Create); 
end; 

end. 

官方文档中,我读到我应该使用TNotifierObjectwho implements IOTAWizardand IOTAMenuWizardinterfaces (From ToolsAPIunit),而不是ExptIntfand ToolsIntf

为了更新示例代码,我执行了以下步骤:

  1. 已从源代码中ExptIntf删除。ToolsIntf
  2. 添加ToolsAPI到使用条款。
  3. 替换TExpertStateTWizardState
  4. 替换esEnabledwsEnabled
  5. 替换RegisterLibraryExpertRegisterPackageWizard

这样做之后,我仍然在TExpertStyle和上有未声明的标识符错误ToolServices

function TPanelEditExpert.GetStyle: TExpertStyle; 
begin
  // show up in the Help menu
  Result := esStandard;
end;

procedure TPanelEditExpert.Execute; 
var
  ModuleName, FormName, FileName: string;
  ModIntf: TIModuleInterface;
begin
  ToolServices.GetNewModuleAndClassName (
    'Panel', ModuleName, FormName, FileName); 
  ModIntf := ToolServices.CreateModuleEx (FileName, FormName,
    'Panel', '', nil, nil,
    [cmNewForm, cmAddToProject, cmUnNamed]);
  ModIntf.ShowSource;
  ModIntf.ShowForm;
  ModIntf.Release;
end;

应该如何更新这些部分和/或在哪里可以找到不使用已弃用单元的示例?

4

1 回答 1

0

Warren Postma 四月份在当地的 Delphi 用户组发表了关于使用 Open Tools API 创建 IDE 插件的演讲。

他的会议记录是在线的,包括指向他的源代码的链接。

注意:他在解析器示例中遇到了问题,在发布的示例代码中可能会也可能不会清理。

于 2016-11-22T13:09:15.547 回答