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

📄 uguihelpdata.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 2 页
字号:

 FLoggedComponents := TLoggedComponents.Create;  //create all needed lists
 FLoggedAliases := TStringList.Create;

 ParseLogFile;                                   //parse the log file
end;


{Frees the parsed data and the object.}
destructor TPureGUIHelpData.Destroy;
begin
 FLoggedAliases.Free;                            //free all lists
 FLoggedComponents.Free;

 inherited Destroy;                              //free the object
end;












{Returns the base name of the file.
~result the base name of the file }
function TPureGUIHelpData.GetBaseName: String;
begin
 Result := ChangeFileExt(ExtractFileName(FLogFilePath), '');
end;



{Parses a definition of a component in the GUI.
~param Line the line defining the component
~result whether the component is not in the contraint }
function TPureGUIHelpData.ParseComponent(const Line: String): Boolean;
var      Component       :TLoggedComponent; //the logged component
         i               :Integer;   //different indices
         Text            :String;    //a part of the line
         code            :Integer;   //error position in string
begin
 Result := True;
 if TrimLeft(Line) <> '' then        //line not empty?
  begin
   i := pos(' ', Line);              //get end of the name of the component
   if not (Line[1] in StartIdentifierChars) or (i = 0) then
    FMessageLogger.AddPositionMessage(FMessageID, FMessageNumber,
                                      'Invalid line in component log file: ' +
                                      ExtractFileName(FLogFilePath) + ': ' +
                                      Line)
   else
    begin
     Component.Name := copy(Line, 1, i - 1); //get the name of the component
     //remove the name from the line
     Text := Trim(copy(Line, i + 1, high(length(Line))));

     i := pos(' ', Text);                    //get end of the position
     if (Text = '') or not (Text[1] in ['0'..'9']) or (i = 0) or
        not ParseRectString(copy(Text, 1, i - 1), Component.Position) then
      FMessageLogger.AddPositionMessage(FMessageID, FMessageNumber,
                                        'Invalid line in component log file: ' +
                                        ExtractFileName(FLogFilePath) + ': ' +
                                        Line)
     else
      begin
       Delete(Text, 1, i);                        //remove the rect
       Text := Trim(Text);                        //and trim it
       i := pos(' ', Text);                       //get end of the help context
       if i = 0 then
        i := Length(Text) + 1;
       //extract the help context
       val(copy(Text, 1, i - 1), Component.HelpContext, code);
       if code <> 0 then
        FMessageLogger.AddPositionMessage(FMessageID, FMessageNumber,
                                          'Invalid line in component log file: ' +
                                          ExtractFileName(FLogFilePath) +
                                          ': ' + Line)
       else
        begin
         Delete(Text, 1, i);                        //remove the help context
         Text := Trim(Text);                        //and trim it
         if (Text <> '') and
            ((Length(Text) <> 1) or not (Text[1] in ['0', '1'])) then
          FMessageLogger.AddPositionMessage(FMessageID, FMessageNumber,
                                            'Invalid line in component log file: ' +
                                            ExtractFileName(FLogFilePath) +
                                            ': ' + Line)
         else
          begin
           Result := Text = '0';                      //not in constraint?
//           Component.InConstraint := not Result;

           if not Result then
            FLoggedComponents.Add(Component);           //add the component

          end; //if valid constrained-flag
        end; //if valid help context
      end; //if valid position
    end; //if valid name of component
  end; //if line not empty
end;


{Parses a definition of an alias of a component.
~param Line the line defining the alias }
procedure TPureGUIHelpData.ParseAlias(Line: String);
var       i               :Integer; //index of separating space
          Alias           :String;  //the help context of the component
begin
 Line := TrimLeft(Line);
 if Line <> '' then                 //line not empty?
  begin
   i := pos(' ', Line);              //get end of the name of aliased component
   if not (Line[1] in StartIdentifierChars) or (i = 0) or
      not (Line[i + 1] in StartIdentifierChars) then
    FMessageLogger.AddPositionMessage(FMessageID, FMessageNumber,
                                      'Invalid line in component log file: ' +
                                      ExtractFileName(FLogFilePath) + ': ' +
                                      Line)
   else
    begin
     Alias := TrimRight(Line);         //get the alias line
     Alias[i] := '=';
     if pos(' ', Alias) <> 0 then
      FMessageLogger.AddPositionMessage(FMessageID, FMessageNumber,
                                        'Invalid line in component log file: ' +
                                        ExtractFileName(FLogFilePath) + ': ' +
                                        Line)
     else
      //both components of the alias known? (may be outside constraint)
      if (FLoggedComponents.FindComponent(Copy(Alias, 1, i - 1)) <> -1) and
         (FLoggedComponents.FindComponent(Copy(Alias, i + 1,
                                               High(Length(Alias)))) <>
          -1) then
       FLoggedAliases.Append(Alias);       //add the alias
    end; //if valid names of components
  end; //if line not empty
end;






{Parses the log file. }
procedure TPureGUIHelpData.ParseLogFile;
var       F               :TextFile; //the log file
          Line            :String;  //each line of the log file
          Code            :Integer; //index in the line
          AllInConstraint :Boolean; //if the form has no contrain
begin
 AssignFile(F, FLogFilePath);
 Reset(F);                          //open the log file
 try
   Line := '';
   if not Eof(F) then               //file not empty?
    repeat
      ReadLn(F, Line);                //skip all leading empty lines
    until (TrimLeft(Line) <> '') or Eof(F);



   if TrimLeft(Line) <> '' then     //line (file) not empty?
    begin
     //try to read help context of window
     val(Trim(Line), FWindowHelpContext, Code);
     if Code <> 0 then                     //not a valid help context?
      FWindowHelpContext := 0                //reset it to not specified
     else
      repeat                                 //skip all following emtpy lines
        ReadLn(F, Line);
      until (TrimLeft(Line) <> '') or Eof(F);
    end;


   AllInConstraint := True;
   while Line <> '' do              //for each line to define a component
    begin
     AllInConstraint := ParseComponent(Line) and AllInConstraint; //parse it
     if Eof(F) then                   //and get the next line
      Line := ''
     else
      ReadLn(F, Line);
    end;
   FHasConstraint := not AllInConstraint;  //save if the form has a constraint

   if not Eof(F) then               //end of file not reached?
    repeat
      ReadLn(F, Line);                //skip all leading emtpy lines
    until (TrimLeft(Line) <> '') or Eof(F);

   while Line <> '' do              //for each line to define an alias
    begin
     ParseAlias(Line);                //parse it
     if Eof(F) then                   //and get the next line
      Line := ''
     else
      ReadLn(F, Line);
    end;
 finally
  CloseFile(F);                     //close the file
 end;
end;

















  { * * *  ***  * * *  ***   TLoggedComponents   ***  * * *  ***  * * *  }


{$INCLUDE ..\..\General\Templates\ListTemplate.inc}


{Returns the index of the component with the name or -1.
~param Name the name of the component to search
~result the index fo the component in the list or -1 if not found }
function TLoggedComponents.FindComponent(const Name: String): Integer;
begin
 Result := 0;                       //search the whole list for the component
 while (Result < FCount) and
       (CompareText(Name, FContent[Result].Name) <> 0) do
  inc(Result);
 if Result = FCount then            //component not in list?
  Result := -1;
end;


end.

⌨️ 快捷键说明

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