Question

Depuis au moins D2007 un fichier de projet peut avoir un fichier source principale avec le nom de base DIFFERENTES. Les démos DevExpress utilisent ceci: Par ex il y a un seul fichier DPR UnboundListDemo.dpr qui sert comme source principale pour les UnboundListDemoD11.dproj et UnboundListDemoD12.dproj.

Maintenant, si j'ai un Project: IOTAProject puis retourne Project.FileName le nom du fichier dproj. Je ne pouvais pas trouver un moyen « officiel » pour obtenir le nom de fichier du DPR. Y a-t-il? On peut obtenir de l'analyse du fichier dproj (voir ) mais je préfère une méthode ToolsAPI.


Modifier Je suis venu avec ce code basé sur réponse de Jon :

function IsProjectSource(const FileName: string): Boolean;
begin
  Result := IsDpr(FileName) or IsBpr(FileName) or IsPackage(FileName);
end;

function GxOtaGetProjectFileName2(Project: IOTAProject; NormalizeBdsProj: Boolean = False): string;
var
  i: Integer;
  Module: IOTAModule;
  Editor: IOTAEditor;
begin
  Result := '';
  if Assigned(Project) then begin
    Result := Project.FileName;
    if NormalizeBdsProj and IsBdsprojOrDproj(Result) then begin
      Module := Project as IOTAModule;
      for i := 0 to Module.ModuleFileCount - 1 do
      begin
        Editor := Module.ModuleFileEditors[i];
        if IsProjectSource(Editor.FileName) then begin
          Result := Editor.FileName;
          Exit;
        end;
      end;
    end;
  end;
end;

où est ... les routines sont GX_GenericUtils .


Edit 2: Comment créer une de ces situations:

  1. Créer une application VCL.
  2. Enregistrer sous MyProject.dproj.
  3. Fermer le projet dans IDE.
  4. Dans l'explorateur de Windows, renomme MyProject.dproj à MyProjectD11.dproj.
  5. A partir de maintenant assurez-vous d'ouvrir MyProjectD11.dproj, pas MyProject.dpr!
Était-ce utile?

La solution

Si vous itérer les rédacteurs en chef sur l'instance IOTAProject, vous trouverez probablement le DPR.

var
  Module: IOTAModule;
  Project: IOTAProject;
  Editor: IOTAEditor;
begin
  // Set Project Here....
  Module := Project as IOTAModule;
  for I := 0 to Module.ModuleFileCount - 1 do
  begin
    Editor := Module.ModuleFileEditors[I];

  end;
end;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top