⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ugenerate.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 4 页
字号:
   FGenerator := nil;
   try
     //create the new generator
     FGenerator := TMakeDocClass(GeneratorClasses.Objects[i]).Create;


     if gcExtractsComments in FGenerator.Capabilities then //uses comments?
      if Assigned(FExtractorClass) then                      //create extractor
       FGenerator.Extractor := FExtractorClass.Create(FGenerator);

     if FGenerator is TCommentDoc then    //uses comments?
      if Assigned(FEvaluatorClass) then     //create evaluator of comments
       TCommentDoc(FGenerator).Evaluator :=
                               FEvaluatorClass.Create(TCommentDoc(FGenerator));

     if Assigned(OldGen) then             //not the first generator?
      begin
       FGenerator.Files := OldGen.Files;    //use parsed data

       //both generators use comments?
       if (gcExtractsComments in FGenerator.Capabilities) and
          (gcExtractsComments in OldGen.Capabilities) then
        //assign the options of the old helper objects
        if Assigned(FExtractorClass) and
           Assigned(FGenerator.Extractor) then
         AssignExtractorOptions(OldGen.Extractor);

       //both generators evaluate comments?
       if (FGenerator is TCommentDoc) and (OldGen is TCommentDoc) then
        //assign the options of the evaluators
        if Assigned(FEvaluatorClass) and
           Assigned(TCommentDoc(FGenerator).Evaluator) then
         AssignEvaluatorOptions(TCommentDoc(OldGen).Evaluator);

       AssignGeneratorOptions(OldGen);      //copy the options of the old one
      end; //if assigned(OldGen)

   finally
    OldGen.Free;                          //free the old generator
   end;

   GeneratorLoadOptionsFromFile(FIniFileName); //initialize options

   if Assigned(FOnGeneratorChanged) then       //notify listeners
    FOnGeneratorChanged(Self);
  end; //if valid and different class given

 Result := i <> -1;                       //return whether class was found
end;


{Changes the extractor of comments.
~param Identification the identification of the class of extractors to use;
                      if not found, it's searched as the name of the class
~result whether the specified extractor class has been found }
function TGeneratorManager.ChangeExtractorByName(const Identification:
                                                              String): Boolean;
var      i                :Integer;     //index of class of the new extractor
         OldExtract       :TCommentExtractor; //old extractor of the comments
begin
 //try to find the extractor by the identification
 i := ExtractorClasses.Count - 1;
 while (i >= 0) and
       (CompareText(TCommentExtractorClass(ExtractorClasses.Objects[i]).
                       GetDescription.Identification, Identification) <> 0) do
  Dec(i);

 //if not found fall back to name of class
 if i = -1 then
  i := ExtractorClasses.IndexOf(Identification);


 if (i <> -1) and                              //valid and new extractor given?
    (TCommentExtractorClass(ExtractorClasses.Objects[i]) <>
     FExtractorClass) then
  begin
   FExtractorClass := TCommentExtractorClass(ExtractorClasses.Objects[i]);
   //generator uses comments (and an extractor)?
   if gcExtractsComments in FGenerator.Capabilities then
    begin
     //different class given?
     if (not Assigned(FGenerator.Extractor) or
         (FExtractorClass <> FGenerator.Extractor.ClassType)) then
      begin
       OldExtract := FGenerator.Extractor;           //unlink the old extractor
       FGenerator.Extractor := nil;
       try
         FGenerator.Extractor :=                     //create the new extractor
                               FExtractorClass.Create(TCommentDoc(FGenerator));

         if Assigned(OldExtract) then                //not the first extractor?
          //assign the options of the old one
          AssignExtractorOptions(OldExtract);
       finally
        OldExtract.Free;                             //free the old extractor
       end;
      end; //if different class of extractors
     ExtractorLoadOptionsFromFile(FIniFileName);   //initialize options
    end; //if FGenerator is TCommentDoc

   if Assigned(FOnExtractorChanged) then         //notify listeners
    FOnExtractorChanged(Self);
  end; //if i <> -1

 Result := i <> -1;                       //return whether class was found
end;


{Changes the evaluator.
~param Identification the identification of the class of evaluators to use;
                      if not found, it's searched as the name of the class
~result whether the specified evaluator class has been found }
function TGeneratorManager.ChangeEvaluatorByName(const Identification:
                                                              String): Boolean;
var      i                :Integer;     //index of class of the new evaluator
         OldEval          :TCommentEvaluator; //old evaluator of the comments
begin
 //try to find the evaluator by the identification
 i := EvaluatorClasses.Count - 1;
 while (i >= 0) and
       (CompareText(TCommentExtractorClass(EvaluatorClasses.Objects[i]).
                        GetDescription.Identification, Identification) <> 0) do
  Dec(i);

 //if not found fall back to name of class
 if i = -1 then
  i := EvaluatorClasses.IndexOf(Identification);


 if (i <> -1) and                              //valid and new evaluator given?
    (TCommentEvaluatorClass(EvaluatorClasses.Objects[i]) <>
     FEvaluatorClass) then
  begin
   FEvaluatorClass := TCommentEvaluatorClass(EvaluatorClasses.Objects[i]);
   //generator uses comments (and an evaluator)?
   if FGenerator is TCommentDoc then
    begin
     //different class given?
     if (not Assigned(TCommentDoc(FGenerator).Evaluator) or
         (FEvaluatorClass <> TCommentDoc(FGenerator).Evaluator.ClassType)) then
      begin

       //unlink the old evaluator
       OldEval := TCommentDoc(FGenerator).Evaluator;
       TCommentDoc(FGenerator).Evaluator := nil;
       try
         TCommentDoc(FGenerator).Evaluator :=        //create the new evaluator
                               FEvaluatorClass.Create(TCommentDoc(FGenerator));

         if Assigned(OldEval) then                   //not the first evaluator?
          //assign the options of the old one
          AssignEvaluatorOptions(OldEval);
       finally
        OldEval.Free;                                //free the old evaluator
       end;
      end;
     EvaluatorLoadOptionsFromFile(FIniFileName);   //initialize options
    end;

   if Assigned(FOnEvaluatorChanged) then         //notify listeners
    FOnEvaluatorChanged(Self);
  end;

 Result := i <> -1;                       //return whether class was found
end;











{Generates the documentation of the parsed data.
~param Files if not nil, a list of additional files of user documentation
~result whether the generating was successful }
function TGeneratorManager.Generate(Files: TStrings): Boolean;
         //the information to generate the documentation
var      Info             :TGenerationInformation;
begin
 Assert(Assigned(FGenerator));

 FGenerator.ResetForNewGeneration;             //reset the generator

 Assert(not (gcExtractsComments in FGenerator.Capabilities) or
        Assigned(FGenerator.Extractor));
 Assert(not (FGenerator is TCommentDoc) or
        Assigned(TCommentDoc(FGenerator).Evaluator));

 //set information to generate documentation
 FillChar(Info, SizeOf(Info), 0);
 Info.Kind := dgkDelphiDoc;
 Info.PascalSource := FGenerator.Files;  //a bit funny, ... but for now it's OK
 Info.UserDocumentation := Files;

 Result := FGenerator.GenerateDocumentation(Info);  //generate documentation
end;

{Generates the user documentation.
~param Files the list of files of user documentation
~result whether the generating was successful }
function TGeneratorManager.GenerateOnlyUserDocumentation(Files: TStrings):
                                                                       Boolean;
         //the information to generate the documentation
var      Info             :TGenerationInformation;
begin
 Assert(Assigned(FGenerator));
 if gcExtractsComments in FGenerator.Capabilities then   //can format text?
  begin
   Assert(Assigned(FGenerator.Extractor));
   Assert(not (FGenerator is TCommentDoc) or
          Assigned(TCommentDoc(FGenerator).Evaluator));

   Assert(Assigned(Files));

   FGenerator.ResetForNewGeneration;             //reset the generator

   //set information to generate documentation
   FillChar(Info, SizeOf(Info), 0);
   Info.Kind := dgkUserDoc;
   Info.UserDocumentation := Files;

   //generate user documentation
   Result := FGenerator.GenerateDocumentation(Info);
  end
 else
  raise Exception.Create('Generator does not support user documentation!');
end;

{Generates documentation as a help on a GUI.
~param LogFiles the list of log files containing the data about the GUI
~param Files    if not nil, a list of additional files of user documentation
~result whether the generating was successful }
function TGeneratorManager.GenerateGUIHelp(LogFiles: TStrings;
                                           Files: TStrings): Boolean;
         //the information to generate the documentation
var      Info             :TGenerationInformation;
begin
 Assert(assigned(FGenerator));

 //can generate user documentation?
 if gcGUIHelp in FGenerator.Capabilities then
  begin
   Assert(not (gcExtractsComments in FGenerator.Capabilities) or
          Assigned(FGenerator.Extractor));
   Assert(not (FGenerator is TCommentDoc) or
          Assigned(TCommentDoc(FGenerator).Evaluator));

   FGenerator.ResetForNewGeneration;             //reset the generator

   //set information to generate documentation
   FillChar(Info, SizeOf(Info), 0);
   Info.Kind := dgkGUIHelp;
   Info.UserDocumentation := Files;
   Info.GUIHelpLogFiles := LogFiles;
   Info.MainIndexRoot := FGUIMainIndexRoot;

   //generate documentation about the GUI
   Result := FGenerator.GenerateDocumentation(Info);
  end
 else
  raise Exception.Create('Generator does not support user documentation!');
end;













{Resets the generator to its default values. }
procedure TGeneratorManager.ResetGenerator;
var       OldGen           :TMakeDoc;         //the previous generator object
begin
 OldGen := FGenerator;                        //get the generator
 FGenerator := nil;                           //don't free it automatically
 try
   //create a new generator object
   FGenerator := TMakeDocClass(OldGen.ClassType).Create;

   //generator uses comments (and an extractor)?
   if gcExtractsComments in FGenerator.Capabilities then
    if Assigned(FExtractorClass) then           //has extractor of comments?
     begin
      //create the new extractor of comments
      FGenerator.Extractor := FExtractorClass.Create(FGenerator);
      //assign the options of the old one
      AssignExtractorOptions(OldGen.Extractor);
     end;

   if FGenerator is TCommentDoc then          //has helper objects?
    if assigned(FEvaluatorClass) then           //has evaluators?
     begin
      //create the new extractor
      TCommentDoc(FGenerator).Evaluator :=
                              FEvaluatorClass.Create(TCommentDoc(FGenerator));
      //assign the options of the old one
      AssignEvaluatorOptions(TCommentDoc(OldGen).Evaluator);
     end;
 finally
  OldGen.Free;                                //free the old generator object
 end;
end;

{Sets options of the generator from the list.
~param Options the options to set in format "Option=Value" per entry}
procedure TGeneratorManager.GeneratorLoadOptionList(Options: TStrings);
begin
 FGenerator.GetOptions.LoadOptionList(Options);    //set the options
end;

{Loads the options of the generator from the file.
~param FileName the name of the file to load the options from }
procedure TGeneratorManager.GeneratorLoadOptionsFromFile(const FileName:
                                                                       String);
var       Ini      :TIniFile;             //the ini file containing the options
begin
{$IFNDEF LINUX}
 Assert((Pos('\', FileName) <> 0) or (Pos(':', FileName) <> 0));
{$ENDIF}

 Ini := TIniFile.Create(FileName);        //open the ini file
 try
   GeneratorLoadOptionsFromIniFile(Ini);  //read the options
 finally
  Ini.Free;                               //close the file
 end;
end;

{Loads the options of the generator from the ini file.
~param Ini the ini file to load the options from }
procedure TGeneratorManager.GeneratorLoadOptionsFromIniFile(Ini:
                                                               TCustomIniFile);
begin
 FGenerator.GetOptions.LoadAllIniOptions(Ini);     //load the options
 FGenerator.GetOptions.LoadIniOptions(Ini);
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -