Search code examples
pascalscripthelpndoc

Why is my script not building in HelpNDoc? Error: Unknown name


I am trying to write a script:

const
  // Define the output file
  OUTPUT_FILE = 'd:\topics.txt';

var
  // Current topic ID
  aTopicId: string;
  // List of output
  aList: TStringList;

begin
  // Init list
  aList := TStringList.Create;
  aList.Add('Topic Caption | Help ID | Help Context | Meta Description');
  try
    // Get first topic
    aTopicId := HndTopics.GetTopicFirst();
    // Loop through all topics
    while aTopicId <> '' do
    begin
      // Add the topic to the list
      aList.Add(Format('%s | %s | %d | %s', [
        HndTopics.GetTopicCaption(aTopicId),
        HndTopics.GetTopicHelpId(aTopicId),
        HndTopics.GetTopicHelpContext(aTopicId),
        HndTopics.GetTopicDescription(aTopicId)        
      ]));
      // Get next topic
      aTopicId := HndTopics.GetTopicNext(aTopicId);
    end;
    // Create the file
    aList.SaveToFile(OUTPUT_FILE);
  finally
    aList.Free;
  end;
end.

When I build it in HelpNDoc:

Build Error

Why is it saying:

[Error] script(9, 3): Unknown name "aList"


Solution

  • The authors of HelpNDoc provided some clarification about this issue. Starting with HelpNDoc 7, you need to add the var keyword each time you change the type: Migrating scripts from V6 to V7.

    So my variable declaration section needed to be changed to something like:

    var
      // Current topic ID
      aTopicId: string;
    var
      // List of output
      aList: TStringList;
    

    This is a limitation of HelpNDoc's scripting engine.