首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从delphi IDE expert枚举IDE窗体

如何从delphi IDE expert枚举IDE窗体
EN

Stack Overflow用户
提问于 2011-05-30 05:03:34
回答 2查看 737关注 0票数 4

我在一个delphi IDE专家中工作,我需要枚举所有由Delphi IDE显示的表单,目前我正在使用Screen.Forms属性,但我想知道是否存在使用OTA的另一种方法。因为只有当我的专家是BPL时,才能使用Screen.Forms,但现在我正在迁移到dll专家。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-30 05:55:42

Screen.Forms仍然可以在动态链接库中工作。只需确保在选择了“使用运行时包”链接器选项的情况下编译DLL即可。这样,您的DLL将使用与集成开发环境相同的VCL实例,并且您将可以访问所有相同的全局变量,包括Screen

票数 8
EN

Stack Overflow用户

发布于 2011-05-30 05:59:30

使用OpenToolsAPI完全可以做到这一点。

要提取IDE中所有打开的表单的列表,可以使用如下代码:

代码语言:javascript
运行
复制
procedure GetOpenForms(List: TStrings);
var
  Services: IOTAModuleServices;
  I: Integer;
  Module: IOTAModule;
  J: Integer;
  Editor: IOTAEditor;
  FormEditor: IOTAFormEditor;
begin
  if (BorlandIDEServices <> nil) and (List <> nil) then
  begin
    Services := BorlandIDEServices as IOTAModuleServices;
    for I := 0 to Services.ModuleCount - 1 do
    begin
      Module := Services.Modules[I];
      for J := 0 to Module.ModuleFileCount - 1 do
      begin
        Editor := Module.ModuleFileEditors[J];
        if Assigned(Editor) then
          if Supports(Editor, IOTAFormEditor, FormEditor) then
             List.AddObject(FormEditor.FileName,
               (Pointer(FormEditor.GetRootComponent)));
      end;
    end;
  end;
end;

请注意,该StringList中的指针是一个IOTAComponent。要将此解析为TForm实例,您必须更深入地挖掘。未完待续。

还可以通过向IOTAServices添加IOTAIDENotifier类型的通知程序来跟踪在集成开发环境中打开的所有表单,如下所示:

代码语言:javascript
运行
复制
type
  TFormNotifier = class(TNotifierObject, IOTAIDENotifier)
  public
    procedure AfterCompile(Succeeded: Boolean);
    procedure BeforeCompile(const Project: IOTAProject; var Cancel: Boolean);
    procedure FileNotification(NotifyCode: TOTAFileNotification;
      const FileName: String; var Cancel: Boolean);
  end;

procedure Register;

implementation

var
  IdeNotifierIndex: Integer = -1;

procedure Register;
var
  Services: IOTAServices;
begin
  if BorlandIDEServices <> nil then
  begin
    Services := BorlandIDEServices as IOTAServices;
    IdeNotifierIndex := Services.AddNotifier(TFormNotifier.Create);
  end;
end;

procedure RemoveIdeNotifier;
var
  Services: IOTAServices;
begin
  if IdeNotifierIndex <> -1 then
  begin
    Services := BorlandIDEServices as IOTAServices;
    Services.RemoveNotifier(IdeNotifierIndex);
  end;
end;

{ TFormNotifier }

procedure TFormNotifier.AfterCompile(Succeeded: Boolean);
begin
  // Do nothing
end;

procedure TFormNotifier.BeforeCompile(const Project: IOTAProject;
  var Cancel: Boolean);
begin
  // Do nothing
end;

procedure TFormNotifier.FileNotification(NotifyCode: TOTAFileNotification;
  const FileName: String; var Cancel: Boolean);
begin
  if BorlandIDEServices <> nil then
    if (NotifyCode = ofnFileOpening) then
    begin
      //...
    end;
end;

initialization

finalization
  RemoveIdeNotifier;

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

https://stackoverflow.com/questions/6170407

复制
相关文章

相似问题

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