You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

HelpNDoc 5脚本调用GetTagsAssociatedWithTopic及TStringDynArray报错求助

解决HelpNDoc 5脚本获取主题标签的问题

1. 修正函数调用错误

你遇到的“identifient non déclaré GetTagsAssociatedWithTopic”错误,核心原因是函数归属对象引用错误:HelpNDoc 5中获取主题关联标签的函数不属于HndTags,而是属于HndTopicsTags对象。正确的调用应为HndTopicsTags.GetTagsAssociatedWithTopic(aTopicId)。

2. 处理TStringDynArray相关问题

类型识别问题

HelpNDoc 5的脚本环境已内置TStringDynArray类型,无需自行定义。出现“unknown type”或“Record required”错误,通常是以下原因:

  • 脚本未正确加载HelpNDoc核心单元(自带的ExportHelpIdsandContexts.hnd.pas默认已包含,可检查开头uses语句是否完整)
  • 仍存在对象引用错误,确认调用时使用的是HndTopicsTags而非其他对象

动态数组转字符串

GetTagsAssociatedWithTopic返回的是TStringDynArray(字符串动态数组),无法直接传入Format函数,需先拼接为单个字符串。可添加如下辅助函数完成转换:

function StringArrayToString(const AArray: TStringDynArray; const ADelimiter: string): string;
var
  I: Integer;
begin
  Result := '';
  if Length(AArray) = 0 then Exit;
  Result := AArray[Low(AArray)];
  for I := Low(AArray)+1 to High(AArray) do
    Result := Result + ADelimiter + AArray[I];
end;

修改后的核心代码片段:

var
  aTags: TStringDynArray;
  tagStr: string;
begin
  aTags := HndTopicsTags.GetTagsAssociatedWithTopic(aTopicId);
  tagStr := StringArrayToString(aTags, ', '); // 用逗号分隔标签
  aList.Add(Format('%s | %s | %d | %s', [
          HndTopics.GetTopicCaption(aTopicId),
          HndTopics.GetTopicHelpId(aTopicId),
          HndTopics.GetTopicHelpContext(aTopicId),
          tagStr
        ]));
end;

完整修改示例(基于自带脚本)

procedure GenerateOutput;
var
  aList: TStringList;
  aTopicId: string;
  aTags: TStringDynArray;
  tagStr: string;
begin
  aList := TStringList.Create;
  try
    // 添加表头
    aList.Add('主题标题 | 帮助ID | 帮助上下文 | 标签');
    // 遍历所有主题
    aTopicId := HndTopics.GetFirstTopicId;
    while aTopicId <> '' do
    begin
      aTags := HndTopicsTags.GetTagsAssociatedWithTopic(aTopicId);
      tagStr := StringArrayToString(aTags, ', ');
      aList.Add(Format('%s | %s | %d | %s', [
              HndTopics.GetTopicCaption(aTopicId),
              HndTopics.GetTopicHelpId(aTopicId),
              HndTopics.GetTopicHelpContext(aTopicId),
              tagStr
            ]));
      aTopicId := HndTopics.GetNextTopicId(aTopicId);
    end;
    // 导出到文件
    aList.SaveToFile(HndUtils.GetUserDocumentsFolder + '\HelpIdsWithTags.txt');
    HndUtils.ShowMessage('导出完成,文件路径:' + HndUtils.GetUserDocumentsFolder + '\HelpIdsWithTags.txt');
  finally
    aList.Free;
  end;
end;

// 辅助转换函数
function StringArrayToString(const AArray: TStringDynArray; const ADelimiter: string): string;
var
  I: Integer;
begin
  Result := '';
  if Length(AArray) = 0 then Exit;
  Result := AArray[Low(AArray)];
  for I := Low(AArray)+1 to High(AArray) do
    Result := Result + ADelimiter + AArray[I];
end;

内容的提问来源于stack exchange,提问作者dex ash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 21:45:30