2016-03-10 30 views
2

我寫了一個OpenTools嚮導,用於爲自定義項目類型創建一個框架。它確實有效,項目和單位已經正確創建。但是,如何編輯.dpk或.dpk文件的require子句?Delphi OpenTools API - 編輯項目需要子句

ModuleServices.CreateModule(MyIOTAProjectCreatorInterface)的調用僅給出了.dproj文件。

回答

3

在我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

完美,非常有幫助,謝謝魯迪。 –