我已经编写了一个OpenTools向导来为自定义项目类型创建框架。它确实起作用,并且项目和单元已正确创建。但是,如何编辑.dpk或.dpk文件的require子句?

调用ModuleServices.CreateModule(MyIOTAProjectCreatorInterface)仅给我.dproj文件。

最佳答案

在我的VCL Component Installer中(由于XE,这是Delphi 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部分。我花了一段时间才找到答案。

关于delphi - Delphi OpenTools API-编辑项目require子句,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35918198/

10-13 08:38
查看更多