HelpNDoc Pascal脚本是否支持结构?

时间:2019-05-29 04:32:28

标签: pascalscript helpndoc

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

MyTopic
    TopicID : String;
    HelpID : Integer;

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

我尝试使用这种type / record语法,但是失败。

更新

我定义了typeprocedure

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文档时,遇到了一个问题:

HelpNDoc Error

说明here中的HelpNDoc API。

我的代码有问题吗?

1 个答案:

答案 0 :(得分:1)

我决定采用另一种方法,并使用了一种更简单的技术:

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数组。因此,现在可以根据需要列出弹出帮助。