首页 > 解决方案 > HelpNDoc Pascal 脚本是否支持结构?

问题描述

我正在尝试创建一个结构:

MyTopic
    TopicID : String;
    HelpID : Integer;

我想创建一个由这些结构组成的数组,以便对它们进行排序。

我曾尝试使用此type/record语法,但它失败了。

更新

我定义了这个type并且procedure

type
    TMyTopicRecord = record
        idTopic : String;
        idContextHelp : integer;
    End;

procedure GetSortedTopicIDs(aTopics : array of String; size : Integer);
var
    aMyTopicRecords : array of TMyTopicRecord;
    temp : TMyTopicRecord;
    iTopic, i, j : Integer;
begin
    // Init the array
    SetLength(aMyTopicRecords, size); 

    // Fill the array with the existing topid ids.
    // Get the context ids at the same time.
    for iTopic := 0 to size - 1 do
        aMyTopicRecords[iTopic].idTopic := aTopics[iTopic];
        aMyTopicRecords[iTopic].idContextHelp := HndTopics.GetTopicHelpContext(aTopics[iTopic]);

    // Sort the array on context id
    for i := size-1 DownTo 1 do
    for j := 2 to i do
        if (aMyTopicRecords[j-1].idContextHelp > aMyTopicRecords[j].idContextHelp) Then
        begin
            temp := aMyTopicRecords[j-1];
            aMyTopicRecords[j-1] := aMyTopicRecords[j];
            aMyTopicRecords[j] := temp;
        end;

    // Rebuild the original array of topic ids
    for iTopic := 0 to size - 1 do
        aTopics[iTopic] := aMyTopicRecords[iTopic].idTopic;
end;

该过程在函数的循环中被调用(代码片段):

function GetKeywordsAsHtml(): string;
var
    aKeywordList: THndKeywordsInfoArray;
    aAssociatedTopics: array of string;
    nBlocLevel, nDif, nClose, nCurKeywordLevel, nCurKeywordChildrenCnt: Integer;
    nCurKeyword, nCurKeywordTopic: Integer;
    nCountAssociatedTopics: Integer;
    sCurrentKeyword, sKeywordLink, sKeywordRelated: string;
    sKeywordJsCaption: string;
begin
    Result := '<ul>';
    nBlocLevel := 0;
    try
        aKeywordList := HndKeywords.GetKeywordList(False);
        for nCurKeyword := 0 to length(aKeywordList) - 1 do
        begin
            sCurrentKeyword := aKeywordList[nCurKeyword].id;
            nCurKeywordLevel := HndKeywords.GetKeywordLevel(sCurrentKeyword);
            nCurKeywordChildrenCnt := HndKeywords.GetKeywordDirectChildrenCount(sCurrentKeyword);

            sKeywordLink := '#';
            sKeywordRelated := '[]';

            aAssociatedTopics := HndTopicsKeywords.GetTopicsAssociatedWithKeyword(sCurrentKeyword);
            nCountAssociatedTopics := Length(aAssociatedTopics);
            if nCountAssociatedTopics > 0 then
            begin
                GetSortedTopicIDs(aAssociatedTopics, nCountAssociatedTopics);
                // Code snipped
            end;
        end;
    finally
        Result := Result + '</ul>';
    end;
end;

在 HelpNDoc内部编辑器中编译的脚本没有问题。但是当我去实际构建我的 HTML 文档时,我遇到了一个问题:

帮助NDoc 错误

HelpNDoc API 在这里解释。

我的代码有问题吗?

标签: pascalscripthelpndoc

解决方案


我决定采用不同的方式并使用更简单的技术:

procedure GetSortedTopicIDs(var aTopics : array of String; iNumTopics : Integer);
var
    iTopic : Integer;
    // List of output
    aList: TStringList;
begin
    // Init list
    aList := TStringList.Create;

    // Build a new array of "nnn x"
    //  - nnn is the help context id
    //  - x is the topid id

    // Note: I know that the context ID values are within the range 0 - 200
    for iTopic := 0 to iNumTopics - 1 do
        // We pad the context id with 0. We could increase the padding width to
        // make the script mre useful
        aList.Add(Format('%0.3d %s', [
            HndTopics.GetTopicHelpContext(aTopics[iTopic]),
            aTopics[iTopic]
        ]));

    // Now we sort the new array (which basically sorts it by context id)
    aList.Sort; 

    // Update original array
    for iTopic := 0 to iNumTopics - 1 do
        // We ignore the "nnn " part of the string to get just the topic id
        aTopics[iTopic] := copy(aList[iTopic],5, length(aList[iTopic])-4);

    // Tidy up      
    aList.Free;
end;

这编译,我在它的末尾得到了主题 ID 的排序数组。所以弹出帮助现在按我的意愿列出。


推荐阅读