Delphi OpenTools API - 编辑项目需要子句

问题描述:

我写了一个OpenTools向导,用于为自定义项目类型创建一个框架。它确实有效,项目和单位已经正确创建。但是,如何编辑.dpk或.dpk文件的require子句?Delphi OpenTools API - 编辑项目需要子句

ModuleServices.CreateModule(MyIOTAProjectCreatorInterface)的调用仅给出了.dproj文件。

在我VCL Component Installer(因为XE,这是德尔福IDE的一部分),我做这种方式:

procedure TCompInstallWizard.AddReferenceFiles(InstallProject: IOTAProject; 
    const FileNames: array of string); 
var 
    ReferenceFile: string; 
begin 
    WriteDebugMessage('AddReferenceFiles'); 
    for ReferenceFile in FileNames do 
    if not ContainsFile(InstallProject, ReferenceFile) then 
     InstallProject.AddFile(ReferenceFile, False); 
end; 

与功能IOTAProject.AddFile(FileName, IsUnitOrForm)帮助。请注意,我这样称呼它:

if FPersonality = ppCppBuilder then 
    AddReferenceFiles(InstallProject, 
    ['rtl.bpi', 'designide.bpi', 'vcl.bpi', 'vclactnband.bpi', 
    'vclx.bpi', 'xmlrtl.bpi']) 
else 
    AddReferenceFiles(InstallProject, 
    ['rtl.dcp', 'designide.dcp', 'vcl.dcp', 'vclactnband.dcp', 
    'vclx.dcp', 'xmlrtl.dcp']); 

注意的是,文件说:

{ Call this function to add an arbitrary file to the project. NOTE: some 
    files have special meaning to different projects. For example: adding 
    VCL60.DCP will cause a new entry in a package project's "requires" list 
    while it will be a raw file to any other project type. Set IsUnitOrForm 
    to true for files that are considered items that the project would 
    process directly or indirectly (ie. .pas, .cpp, .rc, etc..) or can be 
    opened in the code editor. For all others, including binary files 
    (.res, .bpi, .dcp, etc..) set this to False. } 
procedure AddFile(const AFileName: string; IsUnitOrForm: Boolean); 

这意味着,如果你添加一个'bla.dcp'它会自动在requires部分的土地,如果你添加'bla.pas'文件,它将登陆contains部分。我花了一段时间才发现。

+0

完美,非常有帮助,谢谢鲁迪。 –