HelpNDoc脚本构建失败,报错Unknown name 'aList' 原因是什么?
HelpNDoc Pascal脚本错误:Unknown name "aList"原因分析
你编写的用于导出HelpNDoc主题信息的Pascal脚本如下:
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.
运行时出现的错误提示:
[Error] script(9, 3): Unknown name "aList"
错误原因
HelpNDoc的脚本引擎基于Delphi语言子集,但默认并未自动引入TStringList所属的Classes单元。在标准Delphi环境中,TStringList类定义在Classes.pas单元内,若脚本中未显式声明引用该单元,脚本引擎会无法识别TStringList类型,进而导致变量aList被判定为未定义的未知名称。
解决方法
在脚本开头的const声明前添加uses Classes;,显式引入包含TStringList的单元,修改后的脚本如下:
uses Classes; 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.
内容的提问来源于stack exchange,提问作者Andrew Truckle
相关产品推荐
相关产品推荐

