Adding a unit automatically to the project

血红的双手。 提交于 2020-01-21 05:06:10

问题


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?


回答1:


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

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);

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




回答2:


Odd.

I used to set my default dpr to contain next to nothing as a result my toolbox was very empty. So if it was in my toolbox it was in the dpr - what are you having problems with - normally if its in the toolbox, its already in the dpr.




回答3:


go Project > Eurekalog Options and disable Eurekalog.



来源:https://stackoverflow.com/questions/10293177/adding-a-unit-automatically-to-the-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!