将单位自动添加到项目 [英] Adding a unit automatically to the project

查看:186
本文介绍了将单位自动添加到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Delphi 7 Delphi 2006 中的组件,我正在使用一个单位需要添加自动删除组件的项目的 .dpr 文件。
像Eureka Log自动将单元ExceptionLog添加到项目文件中的方式:

I am working on a component in Delphi 7 and Delphi 2006, where I am using a unit which I need to add to the .dpr file of the project on which the component is dropped automatically. Like the way Eureka Log automatically adds the unit 'ExceptionLog' to the project file:

任何人都可以告诉我如何以编程方式将一个单位添加到项目文件中在项目中的任何表单上?

Can anyone tell me how to programmatically add a unit to the project file when I drop my component on any form in the project?

推荐答案

您最有可能使用Open Tools API。

You most likely have to use the Open Tools API for that.

此外,还可能需要编写一个 TSelectionEditor 为您的组件触发添加单元(我会尝试RequiresUnit方法)。

Also it might require to write a TSelectionEditor for your component to trigger the adding of the unit (I would try the RequiresUnit method).

虽然有一个简单的方法来添加一个单位活动项目(代码如下)这仅适用于活动项目,这可能不是您将表单所属的项目添加到组件。另外它在使用子句的末尾添加单元。

While there is an easy way to just add a unit to the active project (code below) this just works for the active project which might not be the project the form belongs to you are adding the component to. Also it adds the unit at the end of the uses clause.

uses
  ToolsAPI;

var
  currentProject: IOTAProject;
begin
  currentProject := GetActiveProject();
  currentProject.AddFile('MyUnit.pas', True);

您可以查看 GExperts源代码,因为它包含一个可以解析单元并修改uses子句的类(TUsesManager)。

You can check the GExperts source code because it contains a class (TUsesManager) that can parse units and modify the uses clause.

这篇关于将单位自动添加到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆